Comments (8)
Can you, please, provide an example where you have a need to distinguish two or
more
mocks of the same class ?
Original comment by [email protected]
on 13 Mar 2008 at 10:51
from mockito.
An example would be great.
Frankly speaking, I deliberately removed naming mocks. I felt that naming mocks
is
just a trick to deodorize a smell of big test with too many mocks...
Original comment by [email protected]
on 14 Mar 2008 at 2:05
from mockito.
Consider following code:
//mockOne and mockTwo are of the same class
verify(mockOne).doIt();
veriyf(mockTwo).doIt();
Why do you need names for those mocks? Stack trace will show you line of code
where
verification fails - you will know which interaction/mock failed - just click on
first stack trace element...
Original comment by [email protected]
on 16 Mar 2008 at 2:21
- Added labels: Type-Enhancement
- Removed labels: Type-Defect
from mockito.
Closing to clear backlog.
Please look at our comments, tell us what you think and reopen if you feel like.
Original comment by [email protected]
on 16 Mar 2008 at 2:27
- Changed state: WontFix
from mockito.
I had this problem:
ParkingLot fullLot = mock(ParkingLot.class);
ParkingLot almostFullLot = mock(ParkingLot.class);
ParkingLot emptyLot = mock(ParkingLot.class);
Attendant attendant = new Attendant(lot1, lot2, lot3);
//... Make some lots full and some not, make some rule by which the attendants
park
attendant.park();
verify(lot3).park();
So, it fails. I can verify that it fails. I can put a break point in the for...
loop,
inside the attendant... but because there's just a set of parking lots, I can't
see
which parking lot the attendant's observing / responding to at any time.
It turned out to be a stupid > instead of < - I had to use something other than
Mockito to spot the silly mistake, because I couldn't tell which parking lot
was which.
So, yes, stack traces are fantastic. Names would be helpful when debugging,
even if I
remove them once I've fixed the problem!
Original comment by [email protected]
on 22 Mar 2008 at 1:11
from mockito.
Even just making the mock debug as "Mock of Parking Lot@233725253", with the
mock
object's ID, would do the trick; I can catch that in both the test and the
attendant
and see which is which.
Of course, I could always try stubbing toString()... :P
Original comment by [email protected]
on 22 Mar 2008 at 1:34
from mockito.
OK, I can see that for debugging purposes it would be nice to name mocks.
For now mocks print hashCode value in toString(). Something like that:
"Mock for SomeClass, hashCode: 4323423"
The change is in trunk and will go out with the next release.
Please keep us posted if you come across problems that require explicitly
naming mocks.
Original comment by [email protected]
on 22 Mar 2008 at 6:44
from mockito.
Original comment by [email protected]
on 19 Apr 2009 at 7:40
- Added labels: Milestone-Pre1.7
from mockito.
Related Issues (20)
- @InjectMocks and @Spy cannot be used together when object initialized by mockito HOT 10
- How to spy private method HOT 1
- timeout() should use long instead of int HOT 1
- Move internal class Whitebox to API HOT 1
- Get class of object, superclass if mocked object HOT 3
- Mocking interface method that accepts a varargs parameter does not return the mocked value as expected HOT 1
- Mockito fails to verify JavaFX objects HOT 4
- Add warning about stubbing the final methods in documentation HOT 2
- Mock returning java.util.Optional should return Optional.empty() by default (Java 8) HOT 7
- PowermockitoRunner failes with Java 7u65 and Java 8u11 HOT 3
- Mockito should provide a mechanism for classes to opt out of mocking: @Unmockable HOT 17
- Problem with mocking not overriden method which uses generics HOT 5
- Feature request/idea - "No more interactions" for a single method only HOT 4
- Argument Captor argument is not correct in the documentation. HOT 2
- Support "faking" abstract clases HOT 1
- Please push 1.10.x to maven central
- Multiple argument matchers within the same test method causing issue. HOT 2
- Mockito spy fail to handle abstraction correctly HOT 1
- Addind an InvocationListener to a mock, after it has been created. More specific, make a mock verbose. HOT 3
- Mockito spy is unable to verify protected method call from within an anonymous class HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockito.