funbee / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

New spying feature #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
New spying feature: creates a spy from a genuine object. Spy delegates to
real implementation but allows stubbing and verification. Similar to
partial mocking (known from other frameworks).

Proposed interface:

Foo foo = new Foo();

Foo spy = Mockito.spy(foo);
//also: @Spy annotation

//optional stubbing
Mockito.stub(spy.getStuff()).toReturn("hello");

//optional verification
Mockito.verify(spy).doStuff();

//calling methods on spy invokes the real implementation 
//unless the method is stubbed

spy.someMethod();
spy.getStuff();

Original issue reported on code.google.com by szcze...@gmail.com on 25 Jun 2008 at 1:24

GoogleCodeExporter commented 9 years ago
Looks really good.

How would @Spy annotation work? Is it going to create an object based on a 
default
constructor? To make it consistent spy() method should also allow for:

Foo spy = Mockito.spy(Foo.class);

Original comment by bbankow...@gmail.com on 25 Jun 2008 at 2:36

GoogleCodeExporter commented 9 years ago
Ok then, @Spy annotation is out of the game. Let's not complicate and leave out 
the
default constructors.

Original comment by szcze...@gmail.com on 25 Jun 2008 at 3:04

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 25 Jun 2008 at 6:41

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 25 Jun 2008 at 6:41

GoogleCodeExporter commented 9 years ago
I was thinking about possible scenarios for partial mocking and my conclusion 
is that
the usage of a proposal would be limited. Why? Because it won't allow you to 
stub
private methods and in most of my cases this is what I would like to do.

Original comment by bbankow...@gmail.com on 26 Jun 2008 at 6:44

GoogleCodeExporter commented 9 years ago
mocking private methods? You're a bad boy. When the test starts to be curious 
about a
private method then clearly this method should not be private any more :)

Original comment by szcze...@gmail.com on 12 Jul 2008 at 8:24

GoogleCodeExporter commented 9 years ago
Implemented in 1.5

Original comment by szcze...@gmail.com on 26 Jul 2008 at 8:39

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 26 Jul 2008 at 8:39

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 19 Apr 2009 at 7:40