junit4

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

房东的猫 提交于 2019-11-25 21:55:07
问题 How can I use JUnit4 idiomatically to test that some code throws an exception? While I can certainly do something like this: @Test public void testFooThrowsIndexOutOfBoundsException() { boolean thrown = false; try { foo.doStuff(); } catch (IndexOutOfBoundsException e) { thrown = true; } assertTrue(thrown); } I recall that there is an annotation or an Assert.xyz or something that is far less kludgy and far more in-the-spirit of JUnit for these sorts of situations. 回答1: JUnit 4 has support for

Maven does not find JUnit tests to run

人盡茶涼 提交于 2019-11-25 20:24:32
I have a maven program, it compiles fine. When I run mvn test it does not run any tests (under TESTs header says There are no tests to run. ). I've recreated this problem with a super simple setup which I will include below as well as the output when run with -X . The unit tests run fine from eclipse (both with its default junit package and when I instead include the junit.jar downloaded by maven). Also mvn test-compile correctly creates the class under test-classes. I am running this on OSX 10.6.7 with Maven 3.0.2 and java 1.6.0_24. Here is the directory structure: /my_program/pom.xml /my