Top "Junit" questions

Popular unit testing framework for Java and Scala.

How do you assert that a certain exception is thrown in JUnit 4 tests?

How can I use JUnit4 idiomatically to test that some code throws an exception? While I can certainly do something …

java exception junit junit4 assert
Mockito : how to verify method was called on an object created within a method?

I am new to Mockito. Given the class below, how can I use Mockito to verify that someMethod was invoked …

java unit-testing junit mockito
How to run test methods in specific order in JUnit4?

I want to execute test methods which are annotated by @Test in specific order. For example: public class MyTest { @Test …

java unit-testing junit junit4
How to get the path of src/test/resources directory in JUnit?

I know I can load a file from src/test/resources with: getClass().getResource("somefile").getFile() But how can I …

java junit
How to run JUnit test cases from the command line

I would like to run JUnit test cases from the command line. How can I do this?

unit-testing command-line junit
Mockito How to mock and assert a thrown exception?

I'm using mockito in a junit test. How do you make an exception happen and then assert that it has (…

java exception-handling junit mockito
When do Java generics require <? extends T> instead of <T> and is there any downside of switching?

Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected = null; …

java generics junit
How to verify a method is called two times with mockito verify()

I want to verify if a method is called at least once through mockito verify. I used verify and it …

junit mockito verify
Testing Private method using mockito

public class A { public void method(boolean b){ if (b == true) method1(); else method2(); } private void method1() {} private void method2() {} } …

java junit mockito
Java/ JUnit - AssertTrue vs AssertFalse

I'm pretty new to Java and am following the Eclipse Total Beginner's Tutorials. They are all very helpful, but in …

java junit assert junit4 assertions