java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
Add hamcrest-all-X.X.jar to your classpath. Latest version as of Feb 2015 is 1.3: http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q=
Add hamcrest-all-X.X.jar to your classpath. Latest version as of Feb 2015 is 1.3: http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q=
How about Thread.sleep(2000); ? 🙂
I fixed the issue by right clicking the test and selecting ‘Run Configurations’ and changing the “Test runner:” selection to ‘JUnit 4’ as shown here: I ran the test again and it worked.
And in classic fashion, I found what I was looking for moments after posting the question. Hopefully this will make it easier for the next person to find without first having to know what it’s called. The magic method is the deceptively short-named as, which is part of another interface that AbstractAssert implements: Descriptable, not … Read more
That’s not testing, that’s “looking manually at output” (known in the biz as LMAO). More formally it’s known as “looking manually for abnormal output” (LMFAO). (See note below) Any time you change code, you must run the app and LMFAO for all code affected by those changes. Even in small projects, this is problematic and … Read more
This appears to occur because only the source code is compiling when you use mvn clean compile (I’m using maven 3.1.0 so I’m not sure if it always behaved like this). If you run mvn test, the test code will compile as well, but then it runs the tests (which may not be immediately desirable … Read more
I have found Embedded MongoDB library which looks quite promising and does what you have asked for. Currently supports MongoDB versions: 1.6.5 to 3.1.6, provided the binaries are still available from the configured mirror. Here is short example of use, which I have just tried and it works perfectly: public class EmbeddedMongoTest { private static … Read more
There’s new approach with Android Testing Support Library (currently androidx.test:runner:1.1.1). Kotlin updated example: class ExampleInstrumentedTest { lateinit var instrumentationContext: Context @Before fun setup() { instrumentationContext = InstrumentationRegistry.getInstrumentation().context } @Test fun someTest() { TODO() } } If you want also app context run: InstrumentationRegistry.getInstrumentation().targetContext Full running example: https://github.com/fada21/AndroidTestContextExample Look here: What’s the difference between getTargetContext() and … Read more
If you’re wondering specifically about the examples in the JUnit FAQ, such as the basic test template, I think the best practice being shown off there is that the class under test should be instantiated in your setUp method (or in a test method). When the JUnit examples create an ArrayList in the setUp method, … Read more
Although I agree with @assylias that using @BeforeClass is a classic solution it is not always convenient. The method annotated with @BeforeClass must be static. It is very inconvenient for some tests that need instance of test case. For example Spring based tests that use @Autowired to work with services defined in spring context. In … Read more