Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Maven测试和例外测试注释_Java_Maven_Exception_Junit_Maven Plugin - Fatal编程技术网

Java Maven测试和例外测试注释

Java Maven测试和例外测试注释,java,maven,exception,junit,maven-plugin,Java,Maven,Exception,Junit,Maven Plugin,我正在使用Maven,并尝试使用Junit进行测试 当我想要声明一个检查是否引发异常的测试时,目前我执行以下操作: @Test public void testAddPlayerWithInvalidBirthdate() throws Exception { boolean test = false; try { this.playerService.add("Jean", "Dupont", new MyCalendar(2010, 12, 21), "te

我正在使用Maven,并尝试使用Junit进行测试

当我想要声明一个检查是否引发异常的测试时,目前我执行以下操作:

@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);
}
这个测试很有效 但当我试着写这篇文章时:

@Test(expected = MinorPersonException.class)
public void testAddPlayerWithInvalidBirthdate() throws Exception {
    this.playerService.add("Jean", "Dupont", new MyCalendar(2010, 12, 21), "test", "test");
}
当我使用
mvn test
处理测试时,maven说异常已经抛出,测试失败了:/

我在pom.xml中使用JUnit4.12

编辑:示例

我的测试班:

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结果:

Results :

Tests in error: 
  PlayerParametersTest.testInvalidFirstName:14 » InvalidName Invalid firstname 
我发现了问题! 我已经扩展了
TestCase