Error:(23, 17) Failed to resolve: junit:junit:4.12
I had the same problem. Solved by adding url for missing repository in the build.gradle file: android { […] repositories { maven { url ‘https://repo1.maven.org/maven2′ } } […] } That’s it.
I had the same problem. Solved by adding url for missing repository in the build.gradle file: android { […] repositories { maven { url ‘https://repo1.maven.org/maven2′ } } […] } That’s it.
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
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
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
Some cases where I have found it useful: mark a test that is incomplete, so it fails and warns you until you can finish it making sure an exception is thrown: try{ // do stuff… fail(“Exception not thrown”); }catch(Exception e){ assertTrue(e.hasSomeFlag()); } Note: Since JUnit4, there is a more elegant way to test that an … Read more
To answer your second question first. If you’re using JUnit 4, you can annotate your test with @Test(expected=MyException.class) to assert that an exception has occured. And to “mock” an exception with mockito, use when(myMock.doSomething()).thenThrow(new MyException());
As it seems the Assert class has been moved from junit.framework to org.junit.Assert in JUnit 4.0 – you can use that instead, it’s not deprecated.
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
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
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