I for one think it could be useful to use Mockito for more test categories than just unit tests.
Performance tests, stress tests, scenario tests, et.c. all come to mind where some partial mocking may be desired, or using real objects with spies attached.
In such cases there might be desirable tallow o for some non-determinism but still run some verifications.
@Brian, you are right. If start() is only calling start(0) then you don't have to verify it. A developer has to decide if method is too simple to be tested. But if later on you add some extra bits to start() then you should add a test to cover it.
On the other hand, there could be the following scenario. Say you wrote the original code and you didn't cover start(). During maintenance some other developer may need to change the start() method and forgets to add a test because he/she is not a TDDer. ;) And introduces a bug. They run your testsuite and all tests come up green. I guess you should also take into account who you're working with.
If I'm working with people I cannot trust then I'd try to cover as much methods as possible even simple ones. But if I'm working on my own or with people I can trust then I'd only cover complex ones.
Max.
@Kristoffer is the approach you showed available as actual software?
Can I grab the source? It looks quite promising.
Having a cleaner syntax for matching the number of interactions would
be nice. This is not the best:
assertEquals(2, union.getMatches().size());[1] http://www.youtube.com/watch?v=xOrgLj9lOwk
Cheers,
Maciej
--
Maciej Biłas
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.
1. Nobody provided a real use case for the feature in question. We believe that convincing use case is a requirement for designing decent APIs
2. Looking at the APIs suggested by users: it feels the feature leads to less readable and therefore harder to maintain tests. Hand-rolled mock could offer significantly better readability.
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
For more options, visit https://groups.google.com/groups/opt_out.
This feels to me like a good use of an argument captor. Do your logic outside of your verification.
--
It's an interesting API, but I feel this proposition too complicated especially with the popAnd, etc.
Let's say I have defined in my project these interfaces :public interface Topic {/*** this must be equivalent to message(payload.getBytes())*/void message(String payload);void message(byte[] payload);}public interface TopicClient {/*** postcondition : the message "COMPLETE" has been sent to the Topic.*/void doSomething();}I want to make a test that tests whether implementations of TopicClient honor the contract.public abstract class AbstractTopicClientTest {protected abstract TopicClient getInstanceToTest(Topic topic);@Testpublic void testCompletedIsSentToTopic() {final Topic topic = mock(Topic.class);TopicClient topicClient = getInstanceToTest(topic);topicClient.doSomething();verify(topic).message("COMPLETED".getBytes());}}Implementations that use the message(String) method will not pass this test.How to do this? Simply stub the topic so that calls to message(String) are indeed equivalent to calls to method message(byte[])public abstract class AbstractTopicClientTest {protected abstract TopicClient getInstanceToTest(Topic topic);@Testpublic void testCompletedIsSentToTopic() {final Topic topic = mock(Topic.class);doAnswer(new Answer<Void>() {@Overridepublic Void answer(InvocationOnMock invocation) throws Throwable {topic.message(((String) invocation.getArguments()[0]).getBytes());return null;}}).when(topic).message(anyString());TopicClient topicClient = getInstanceToTest(topic);topicClient.doSomething();verify(topic).message("COMPLETED".getBytes());}}
I’ll let someone else answer whether it’s possible to do this with Mockito (perhaps PowerMockito). It sounds doubtful to me.
However, this is something that is possible to do with PMD. The API gives you access to the AST of a class, and this scenario you describe is something that could be verified with that API.
--