How to verify that a specific method was not called using Mockito?

How to verify that a method is not called on an object’s dependency? For example: public interface Dependency { void someMethod(); } public class Foo { public bar(final Dependency d) { … } } With the Foo test: public class FooTest { @Test public void dependencyIsNotCalled() { final Foo foo = new Foo(…); final Dependency … Read more

What’s the difference between faking, mocking, and stubbing?

I know how I use these terms, but I’m wondering if there are accepted definitions for faking, mocking, and stubbing for unit tests? How do you define these for your tests? Describe situations where you might use each. Here is how I use them: Fake: a class that implements an interface but contains fixed data … Read more

Running unittest with typical test directory structure

The very common directory structure for even a simple Python module seems to be to separate the unit tests into their own test directory: new_project/ antigravity/ antigravity.py test/ test_antigravity.py setup.py etc. for example see this Python project howto. My question is simply What’s the usual way of actually running the tests? I suspect this is … Read more

How do I use Assert to verify that an exception has been thrown?

How do I use Assert (or other Test class) to verify that an exception has been thrown? 24 s 24 For “Visual Studio Team Test” it appears you apply the ExpectedException attribute to the test’s method. Sample from the documentation here: A Unit Testing Walkthrough with Visual Studio Team Test [TestMethod] [ExpectedException(typeof(ArgumentException), “A userId of … Read more

Unit Testing C Code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 7 years ago. The community reviewed whether to reopen this question 8 months ago and left it closed: Original close reason(s) were not resolved Improve … Read more

How do I generate a stream from a string?

I need to write a unit test for a method that takes a stream which comes from a text file. I would like to do do something like this: Stream s = GenerateStreamFromString(“a,b \n c,d”); 12 s 12 public static Stream GenerateStreamFromString(string s) { var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(s); … Read more

How to mock void methods with Mockito

How to mock methods with void return type? I implemented an observer pattern but I can’t mock it with Mockito because I don’t know how. And I tried to find an example on the Internet but didn’t succeed. My class looks like this: public class World { List<Listener> listeners; void addListener(Listener item) { listeners.add(item); } … Read more