Junit: splitting integration test and Unit tests

You can split them very easily using JUnit categories and Maven. This is shown very, very briefly below by splitting unit and integration tests. Define A Marker Interface The first step in grouping a test using categories is to create a marker interface. This interface will be used to mark all of the tests that … Read more

Hamcrest compare collections

If you want to assert that the two lists are identical, don’t complicate things with Hamcrest: assertEquals(expectedList, actual.getList()); If you really intend to perform an order-insensitive comparison, you can call the containsInAnyOrder varargs method and provide values directly: assertThat(actual.getList(), containsInAnyOrder(“item1”, “item2”)); (Assuming that your list is of String, rather than Agent, for this example.) If … Read more

Testing Private method using mockito

Not possible through mockito. From their wiki Why Mockito doesn’t mock private methods? Firstly, we are not dogmatic about mocking private methods. We just don’t care about private methods because from the standpoint of testing private methods don’t exist. Here are a couple of reasons Mockito doesn’t mock private methods: It requires hacking of classloaders … Read more

What’s the difference between src/androidtest and src/test folders?

src/androidTest is for unit tests that involves android instrumentation. src/test is for pure unit test that do not involve android framework. You can run tests here without running on a real device or on emulator. You can use both folders. Use the first one to test code that use Android framework. Use the second one … Read more

What order are the Junit @Before/@After called?

Yes, this behaviour is guaranteed: @Before: The @Before methods of superclasses will be run before those of the current class, unless they are overridden in the current class. No other ordering is defined. @After: The @After methods declared in superclasses will be run after those of the current class, unless they are overridden in the … Read more

How to assert greater than using JUnit Assert?

Just how you’ve done it. assertTrue(boolean) also has an overload assertTrue(String, boolean) where the String is the message in case of failure; you can use that if you want to print that such-and-such wasn’t greater than so-and-so. You could also add hamcrest-all as a dependency to use matchers. See https://code.google.com/p/hamcrest/wiki/Tutorial: import static org.hamcrest.MatcherAssert.assertThat; import static … Read more