A spy is XUnit pattern where you replace the original implementation with a test double to capture the calls on the object. Later in your test you can verify the object under test has made specific calls on that object
Questions tagged [spy]
425 questions
3
votes
1 answer
Why GetWindowThreadProcessId some times returns 0?
I am injecting a .NET SpyLib in the target address space using remote invocation. I need to send a message to that window's thread which created that remote process via GetWindowThreadProcessId.
I am working on Windows 7. Unfortunately it returns 0…

Usman
- 2,742
- 4
- 44
- 82
3
votes
1 answer
How do I use Spock Spy?
I tried to use Spy test but it did not work. The following class is a Sut.
public class FileManager {
public int removeFiles(String directory) {
int count = 0;
if(isDirectory(directory)) {
String[] files =…

Dongkyun
- 61
- 1
- 6
3
votes
1 answer
Apache camel Junit mock issue
I am writing a JUnit test case for a Route class. I'm facing a problem while mocking ServiceClass inside the Processor class.
public class SaveRouteTest extends CamelTestSupport {
private Exchange exchange;
protected ProducerTemplate…

user5773508
- 91
- 1
- 1
- 8
3
votes
1 answer
Spock: capture return value from a method?
I have a functional test and I use a Spy for the CUT: I want to find out whether a method called in the midst of things returns expected result.
The sort of thing I thought of was something like this:
then:
1 * ch.compileOutputLines(_).size() ==…

mike rodent
- 14,126
- 11
- 103
- 157
3
votes
0 answers
How to mock or disable location.assign while unit testing in angular 4. Karma instance moving to assign parameter route
I am trying to write unit test for logout method:
logout(): Observable {
...
location.assign('/Login');
...
return Observable.of(false);
}
When karma getting line location.assign('/Login'); test result page moving away and…

fullmetaltac
- 41
- 2
3
votes
1 answer
Sinon Spy is never called
I am testing a method A which is calling another method B with different arguments based on conditions. So I would want to spy on B so that I can check whether its called. But the spy is never getting called.
import parent from…

Roy
- 575
- 2
- 8
- 17
3
votes
3 answers
Restore spied/stubbed function with Sinon sandbox
A Sinon sandbox (or sinon instance) is passed from outside to script scope. Internal function (not a method) can be optionally spied/stubbed with Sinon sandbox.
Sinon is involved in some kind of monkey-patching here (not unit-testing) .Sinon sandbox…

Estus Flask
- 206,104
- 70
- 425
- 565
3
votes
1 answer
Using Jasmine spyOn with $resource
I’m trying to use Jasmine spies for testing a controller that calls query on a $resource. I can get a successful test when I write my call to the resource as follows (implementation 1 in the plunk linked below)
function($scope, bagelApiService) {
…

samseven
- 33
- 1
- 6
3
votes
1 answer
mocking/spying private member of super class
I am writing junit test to test BaseClass method. The method uses super class members.
The BaseClass constructor invokes super(arg1, arg2).
In the super(arg1, arg2) constructor there is a dependency injector setting a private member
of the super…

vikas
- 1,318
- 4
- 16
- 33
3
votes
1 answer
How to spy a predefined object with sinon.js
I'm trying to spy window.document with sinon.js. What I do is this:
var document = {
getElementById = function() {}
}
sinon.spy(document, "getElementById").withArgs("foo").returnValues = ["bar"];
What I expect from this call is this:
When…

Aykut Yaman
- 80
- 2
- 9
3
votes
1 answer
jQuery Spy (vertical ticker): after 4th iteration, list items are animated down, increasing the height of container
we are using jQuery spy plugin by Remy Sharp, to build a vertical spy ticker. The module works fine for first 4 iterations and thereafter behaving strange - the list elements are eventually crawling down (increasing the actual height) of the parent…

Jean
- 69
- 4
2
votes
1 answer
Vue Js - mock the $http request using sinon modules
In VueJs project I have list of api request methods in apiList.ts file with below code. Also I am trying to add the unit test case for getUsers, addUser, updateUser methods but unable to mock the http methods(get/post/put). Could someone help to add…

RSKMR
- 1,812
- 5
- 32
- 73
2
votes
1 answer
Mockito: How to Mock objects in a Spy
The application runs in JEE environment.
I wish inject a Spy into a bean under test.
The Spy object has also some beans inside that should be injected. How can inject mocks of those beans into the Spy?
This is the usecase:
package…

amareno
- 53
- 1
- 5
2
votes
2 answers
Test assertions inside test doubles?
Is it a good practice to write a EXPECT(something) inside a test double (e.g. spy or mock) method? To ensure the test double is used in a specific way for testing?
If not, what would be a preferred solution?

user2087347
- 41
- 1
2
votes
2 answers
PowerMockito verifyTimes Always passets private method
public class TestedClass
{
public void publicMethod()
{
privateMethod();
}
private void privateMethod()
{
}
}
I would like to test with PowerMockito that the private method is called exactly once.
Here's…

STSISA
- 61
- 4