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
12
votes
2 answers
Spring (@SpyBean) vs Mockito(@Spy)
What is the difference between @SpyBean from org.springframework.boot.test.mock.mockito.SpyBean and @Spy from org.mockito.Spy?
Using @SpyBean instead of @Spy makes my tests fail.

LiTTle
- 1,811
- 1
- 20
- 37
11
votes
1 answer
Spying on methods in Golang
Is there any way to spy on methods in Golang?
For example, suppose I have
type Object struct {
A int
B string
C *interface{}
}
func (o *Object) Something(val interface{}) {
o.A = 102
// some other business logic under…

Mike Warren
- 3,796
- 5
- 47
- 99
11
votes
2 answers
Mockito - internal method call
I have a class called Availability.java and have two methods.
public Long getStockLevelStage() {
//some logic
getStockLevelLimit();
}
public Long getStockLevelLimit() {
String primaryOnlineArea =…

user2057006
- 617
- 4
- 15
- 28
10
votes
1 answer
Why are some items greyed out in Spy++'s Windows view?
To modify a window of another program, I need to find a specific SysTreeView32 in it using EnumChildWindows API call.
When I inspect the window using Spy++, there are a number of SysTreeView32's in it but all are greyed out except one, which is the…

Hossein
- 4,097
- 2
- 24
- 46
10
votes
3 answers
How to Mock `fs.promises.writeFile` with Jest
I am trying to mock the promise version of fs.writeFile using Jest, and the mocked function is not being called.
Function to be tested (createFile.js):
const { writeFile } = require("fs").promises;
const createNewFile = async () => {
await…

Dan Levy
- 3,931
- 4
- 28
- 48
10
votes
1 answer
Jasmine: How to spy imported function/constructor on ES6?
I am wondering how can I spy/stub function on Jasmine if I am using ES6 imports/exports with babel?
import MobileDetect from 'mobile-detect';
it('should spy MobileDetect', () => {
MobileDetect = jasmine.createSpy('MobileDetect');
});`
The first…

dedirot
- 101
- 1
- 4
9
votes
1 answer
Hide VCL Classes
There are some program tools such as WinSpy++ which will allow you to hover over the Handle of any Control/Component and return the Class Name of that Handle. So for example, if I dropped a TMemo on a Delphi Form and compiled the Application, if I…
user741875
9
votes
1 answer
How can I get my Angular5 spyOn to work as expected?
My test is not detecting changes. Here is my component:
toggleUploadModal() {
const modalRef = this.ngbModal.open(UploadFilesComponent, { size: 'lg', backdrop: 'static' });
modalRef.componentInstance.DeliverableTransaction =…

Shamoon
- 41,293
- 91
- 306
- 570
9
votes
2 answers
How do I mock an exported typescript function in a jasmine test?
I'm trying to mock a function exported from a typescript file in a Jasmine test. I expect the following to mock the imported foo and return the value 1 in the spec for bar.
The mock appears to be uncalled, so I'm clearly missing something. How can I…

Sevenless
- 2,805
- 4
- 28
- 47
9
votes
2 answers
C# is there a a spying framework like mockito for .NET 3.5?
I used to have a very convenient spying framework in java called Mockito. It allows you to mock some of methods on existing objects and also could tell you if others were called (you'd create a spy wrapper for that). Is there anything like that for…

Artem
- 7,275
- 15
- 57
- 97
8
votes
1 answer
Cypress: monitor console output
I know Cypress can print debug information in the browser console, but can it read data from console during tests?
I'm working on a three.js powered app, so I can't properly test the 3d aspects of the app, but I would like to listen for javascript…

Vali Munteanu
- 469
- 3
- 15
8
votes
3 answers
Using Spy Object in PHPUnit?
How can I use Spy Object in PHPUnit?
You can call object in imitation on, and after you can assert how many times it called.
It is Spy.
I know "Mock" in PHPUnit as Stub Object and Mock Object.

Matt - sanemat
- 5,418
- 8
- 37
- 41
8
votes
4 answers
Equivalent of Answers.RETURNS_DEEP_STUBS for a spy in mockito
I have been unable to find a way to use "Deep Stubs" for stubbing methods on a spy in Mockito. What I'm looking to do is something like this:
@Spy private Person person = //retrieve person
@Test
public void testStubbed() {
…

Jared Burgett
- 141
- 1
- 8
8
votes
1 answer
Jasmine Spy to return different values based on argument
I am spying a JS method. I want to return different things based on actual argument to the method. I tried callFake and tried to access arguments using arguments[0] but it says arguments[0] is undefined.
Here is the code -
spyOn(testService,…

Andy897
- 6,915
- 11
- 51
- 86
8
votes
4 answers
Mockito mock a method but use its parameters for the mocked return
There is a method public Content createChild(String path, String contentType, Map properties) I'd like to mock.
I want to mock it that way that the method is called with any kind of arguments, therefore when() wouldn't work because I…

xetra11
- 7,671
- 14
- 84
- 159