Unit testing 在JUnit4中将单元测试标记为预期失败

Unit testing 在JUnit4中将单元测试标记为预期失败,unit-testing,junit,junit4,Unit Testing,Junit,Junit4,JUnit4是否有扩展,允许将某些测试标记为“预期失败” 我想用一些标记标记当前正在开发的特性的测试,例如@wip。对于这些测试,我想确保它们是失败的 我的录取标准: Scenario: A successful test tagged @wip is recorded as failure Given a successful test marked @wip When the test is executed Then the test is recorded as

JUnit4是否有扩展,允许将某些测试标记为“预期失败”

我想用一些标记标记当前正在开发的特性的测试,例如@wip。对于这些测试,我想确保它们是失败的

我的录取标准:

Scenario: A successful test tagged @wip is recorded as failure
    Given a successful test marked @wip
    When the test is executed
    Then the test is recorded as failure.

Scenario: A failing test tagged @wip is recorded as fine
    Given a failing test tagged @wip
    When the test is executed
    Then the test is recorded as fine.

Scenario: A successful test not tagged @wip is recorded as fine
    Given a successful test not tagged @wip
    When the test is executed
    Then the test is recorded as successful.

Scenario: A failing test not tagged with @wip is recorded as failure
    Given a failing test not tagged with @wip
    When the test is executed
    Then the test is recorded as failure.

@Ignore注释表示不必为结果操心。

简短回答,据我所知,没有扩展可以做到这一点,我认为,如果JUnit存在,它将破坏JUnit的整个用途

再回答一下,红色/绿色有点神圣,不应该成为一种习惯。如果您不小心忘记删除规避,并假设所有测试都通过了怎么办

您可以让它期望出现
断言错误
异常

@wip
@Test(expected=AssertionError.class)
public void wipTest() {
   fail("work in progress");
}
在IDE中为此创建快捷方式应该不会太难。当然,我假设您在源代码中用注释标记测试

在我看来,你所问的与JUnit的目的背道而驰,但我确实理解它的用途

另一种方法是使用
WIP
注释实现
WIPRunner
,并以某种方式使其接受使用
WIP
注释的测试失败


如果您正在与BDD框架集成,我会建议一种方法,让它单独运行您标记为@wip的单元测试,并在BDD方法中确定结果是否正确。

哦,是的,但我想为结果操心。特别是,应该执行标记为@wip的测试,它必须失败。确定失败吗?你的意思是你期望出现异常吗?你在描述中描述的与正常测试完全相反。为什么不撤销测试中的所有断言,那么您就达到了预期的效果。@zenog我不确定该评论是否是针对我的?我从来没有真正理解过我所想的问题。我想这样做的理由可能重复:假设QA为一个尚未实现的特性编写了一个集成测试。然后,如果特性仍然没有实现,我希望测试失败(预期失败),如果突然实现,则测试失败(因为这意味着我应该重新进行测试,并将其转换为正常的单元测试)。