我有一个maven程序,编译得很好。 当我运行mvn test它不会运行任何testing(在TESTs头下说There are no tests to run. )。 我已经用一个超级简单的设置重新创build了这个问题,我将在下面包括以及用-X运行时的输出。 unit testing在eclipse中运行良好(包括默认的junit包,以及包含由maven下载的junit.jar)。 另外mvn test-compile正确地创build了testing类下的类。 我正在使用Maven 3.0.2和java 1.6.0_24在OSX 10.6.7上运行此操作。 这是目录结构: /my_program/pom.xml /my_program/src/main/java/ClassUnderTest.java /my_program/src/test/java/ClassUnderTestTests.java pom.xml中: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my_group</groupId> <artifactId>my_program</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>My Program</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> […]
我想执行testing方法,由@Test按照特定的顺序注释。 例如: public class MyTest { @Test public void test1(){} @Test public void test2(){} } 我想确保每次运行MyTest之前都在test2() test1()之前运行test1() ,但是我找不到像@Test(order=xx)这样的注释。 我认为这对于JUnit来说非常重要,如果JUnit的作者不想要订单function ,为什么呢?
我怎样才能使用JUnit4惯用testing一些代码抛出exception? 虽然我当然可以做这样的事情: @Test public void testFooThrowsIndexOutOfBoundsException() { boolean thrown = false; try { foo.doStuff(); } catch (IndexOutOfBoundsException e) { thrown = true; } assertTrue(thrown); } 我记得有一个注释或一个Assert.xyz或者一个远远不够灵活的东西 ,在这种情况下,JUnit的精神要远不止于此。