1. 安装Junit,导入下面的依赖包
2.简单的测试类
1.org.junit.Assert.assertThat(Integer actual, Matcher<? super Integer> matcher) 使用上面的断言方法可以替代其他断言方法
2.使用注解
@Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 测试是否抛出指定异常
@Before @After 在每个测试方法前后执行的方法,比如建立,断开数据库连接
@BeforeClass @AfterClass 在测试类执行前后执行
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
2.简单的测试类
package com.peter.user;
import org.junit.After;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* Unit test for simple App.
*/
public class AppTest
{
@Test
public void AppTest( )
{
assertTrue("sdrt", 8>5);
assertThat(3, is(3));
}
@After
@Test(expected=java.lang.ArrayIndexOutOfBoundsException.class)
public void test2(){
}
}
1.org.junit.Assert.assertThat(Integer actual, Matcher<? super Integer> matcher) 使用上面的断言方法可以替代其他断言方法
2.使用注解
@Test(expected=java.lang.ArrayIndexOutOfBoundsException.class) 测试是否抛出指定异常
@Before @After 在每个测试方法前后执行的方法,比如建立,断开数据库连接
@BeforeClass @AfterClass 在测试类执行前后执行