Questions tagged [test-double]

14 questions
10
votes
2 answers

Testing Promises with multiple thens using testdoublejs

I am using testdouble for stubbing calls within my node.js project. This particular function is wrapping a promise and has multiple then calls within the function itself. function getUser (rethink, username) { return new Promise((resolve, reject)…
ckross01
  • 1,601
  • 2
  • 17
  • 25
5
votes
2 answers

Unit testing cyclomatically complicated but otherwise trivial calculations

Let's say I have a calculator class who primary function is to do the following (this code is simplified to make the discussion easier, please don't comment on the style of it) double pilingCarpetArea = (hardstandingsRequireRemediation = true) ?…
cedd
  • 1,561
  • 1
  • 16
  • 33
2
votes
1 answer

Rspec expect to recieve message with attributes and ignore others

I'm trying to write a spec for a really long time. I need to test this: expect(Foo).to receive(:bar).with(some_args) and everything would work just fine unless Foo received bar only once. But it will receive bar several times for sure so that the…
Ngoral
  • 2,332
  • 2
  • 13
  • 31
2
votes
1 answer

Using expectException and a spy in PHPUnit

I'm using PHPUnit ~5.2 and PHP ~7.0.0. I have a class that wraps a repository, catches the exceptions it throws, calls a logger and then rethrows the exception. public function storeDonation( Donation $donation ) { try { …
Jeroen De Dauw
  • 8,671
  • 10
  • 46
  • 71
1
vote
1 answer

Is it ok to place test double implementations on the main java code

With regards to test doubles is it ok to place them on the main code so that they can be used, when testing code that contains the original library jar as a dependency? There is code that assists me on unit testing (test doubles) on a library I…
gkatzioura
  • 2,077
  • 18
  • 32
1
vote
0 answers

Stub 'require' to throw error using 'testdouble'

I want to stub the 'require' call to a module to throw error. Is there a way to do it using 'testdouble' or 'proxyrequire'?
Lavish
  • 11
  • 3
1
vote
2 answers

PowerkMock-ing BufferedReader runs interminately

What I want to do is to mock newly created instance of BufferedReader. Here's the code that should be tested: A.java ... @Override public String read(String fileName) throws IOException { ... try { fileReader = new…
azizbekian
  • 53,978
  • 11
  • 145
  • 225
1
vote
0 answers

Test doubles for Python standard library HTTP classes

What widely-used Python library is there to make test doubles of the behaviour of low-level HTTP APIs from the Python standard library? I have a code base (Python 2 code) which performs HTTP sessions using the various HTTP-level classes in the…
bignose
  • 24,957
  • 12
  • 70
  • 100
0
votes
0 answers

How to keep test doubles up to date in integrated tests

I am new in development with microservice architecture. After learned Microservice testing by Martin Folwer: https://martinfowler.com/articles/microservice-testing/ Scalable continuous integration:…
0
votes
0 answers

How to write a custom copier for Cpputest

I have a function that returns a gsl::span of a struct object. I have written a mock for this as bellow. class AppleMock:public Apple { public: constexpr AppleMock(gsl::span _trees) noexcept : Apple(_trees) { } …
0
votes
0 answers

Python: during unit test, replace another module's import before it's used

I have module that: Imports a class Instantiates the class + uses it I would like to replace that class with another class before instantiation/use. How can this be done? Here is an analog of my use case. thread_import.py from threading import…
0
votes
1 answer

golang test spy incorrectly comparing equality

I'm in the process of learning go and am adapting a Java Game of Life example from testdouble. However, the test spy I have written incorrectly compares equality of my World struct - the test passes when it should fail, since output(world) is not…
amb85
  • 903
  • 4
  • 18
0
votes
1 answer

An example (or several) about method at() in phpunit

Would anybody, please, show me an example for at method in phpunit test doubles. I don't understand what is its purpose?
jjoselon
  • 2,053
  • 2
  • 15
  • 31
0
votes
3 answers

What is the Kotlin philosophy of test doubles?

What is the Kotlin philosophy of test doubles? With all classes and functions being sealed by default (not open), mocking frameworks like Mockito are clearly not first-class citizens. A lot has already been written about the problem, and also about…
Niel de Wet
  • 6,210
  • 6
  • 50
  • 91