1、Junit的maven依耐
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<!-- <type>...</type> -->
<scope>test</scope>
<!-- <optional>...</optional> -->
<!-- <exclusions>
<exclusion>
<groupId>...</groupId>
<artifactId>...</artifactId>
</exclusion>
</exclusions> -->
</dependency>
2、用@Test註解方法時,測試的類名不能用Test,否則會報錯,@Test不能被識別,不能導包;
3、測試方法一:可以在方法上加@Test註解
import org.junit.Test;
public class TestClass {
@Test
public void TestMethod(){
System.out.println("aaa");
}
}
4、測試方法二:測試類繼承TestCase類(用這種方法類名可以爲Test)
import junit.framework.TestCase;
public class Test extends TestCase{
public void testaaa(){
System.out.println("aaaaaaaa");
}
}