junit3
Junit assert OR condition in my test case
You can use Hamcrest matchers to get a clearer error message here: int i = 2; assertThat(i, Matchers.either(Matchers.is(3)).or(Matchers.is(5)) or int i = 2; assertThat(i, Matchers.anyOf(Matchers.is(3),Matchers.is(5))); This will more clearly explain: Expected: (is <3> or is <5>) but: was <2> showing exactly the expectation and the incorrect value that was provided.
Specifying an order to junit 4 tests at the Method level (not class level)
If you’re sure you really want to do this: There may be a better way, but this is all I could come up with… JUnit4 has an annotation: @RunWith which lets you override the default Runner for your tests. In your case you would want to create a special subclass of BlockJunit4ClassRunner, and override computeTestMethods() … Read more
The differences between JUnit 3 and JUnit 4 [closed]
Java 5 annotations for setup and teardown (@before and @after) instead of setUp() and tearDown(). don’t need to extend TestCase anymore. @Test annotation replaces testSomeMethod() naming convention. static imports for asserts. Junit theories, which allow you to separate data sets from the test itself.
How to provide data files for android unit tests
Option 1: Use InstrumentationTestCase Suppose you got assets folder in both android project and test project, and you put the XML file in the assets folder. in your test code under test project, this will load xml from the android project assets folder: getInstrumentation().getTargetContext().getResources().getAssets().open(testFile); This will load xml from the test project assets folder: getInstrumentation().getContext().getResources().getAssets().open(testFile); … Read more
setUp/tearDown (@Before/@After) why we need them in JUnit?
This (old) JUnit best practices article puts it like this: Do not use the test-case constructor to set up a test case Setting up a test case in the constructor is not a good idea. Consider: public class SomeTest extends TestCase public SomeTest (String testName) { super (testName); // Perform test set-up } } Imagine … Read more
Maven 3 and JUnit 4 compilation problem: package org.junit does not exist
Just to have an answer with the complete solution to help the visitors: All you need to do is add the junit dependency to pom.xml. Don’t forget the <scope>test</scope> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency>