【JUnit】异常测试


测试是否有异常抛出

测试_有异常

1
2
3
4
5
6
7
8
9
10
11
12
package JUnit;

import org.junit.Test;

public class JUnit_04_exception {

@Test(expected = NumberFormatException.class)
public void testA() {
int a = Integer.parseInt("&||!");
}
}

测试结果

测试_无异常

1
2
3
4
5
6
7
8
9
10
11
12
package JUnit;

import org.junit.Test;

public class JUnit_04_exception {

@Test(expected = NumberFormatException.class)
public void testA() {
int a = Integer.parseInt("1");
}
}

测试结果