[英]Maven test and excepted test annotation
I'm using Maven, and I try to make test using Junit. 我正在使用Maven,我尝试使用Junit进行测试。
When I want to declare a test which check if an exception is thrown, currently I do this : 当我想声明一个检查是否抛出异常的测试时,目前我这样做:
@Test
public void testAddPlayerWithInvalidBirthdate() throws Exception {
boolean test = false;
try {
this.playerService.add("Jean", "Dupont", new MyCalendar(2010, 12, 21), "test", "test");
} catch (MinorPersonException e) {
test = true;
}
assertTrue(test);
}
This test works good But when I try to write this : 这个测试很好但是当我尝试写这个:
@Test(expected = MinorPersonException.class)
public void testAddPlayerWithInvalidBirthdate() throws Exception {
this.playerService.add("Jean", "Dupont", new MyCalendar(2010, 12, 21), "test", "test");
}
And when I process the tests with mvn test
, maven says the Exception has been thrown and the test has failed :/ 当我使用
mvn test
处理mvn test
,maven说抛出异常并且测试失败:/
I'm using JUnit 4.12 in my pom.xml 我在我的pom.xml中使用JUnit 4.12
EDIT : Example 编辑:示例
My test class : 我的考试班:
public class PlayerParametersTest extends TestCase {
@Test(expected = InvalidNameException.class)
public void testInvalidFirstName() throws Exception {
new Player("", "Dupont", new MyCalendar(1980, 03, 17), "test", "test");
}
}
Maven result : Maven结果:
Results :
Tests in error:
PlayerParametersTest.testInvalidFirstName:14 » InvalidName Invalid firstname
I've found the issue! 我发现了这个问题! I've had extended
TestCase
我已经扩展了
TestCase
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.