gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:04:34 27 4
gpt4 key购买 nike

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.

最佳答案

简短回答,据我所知,没有扩展可以做到这一点,并且我认为如果存在,它将破坏JUnit的全部目的。

更长的答案,红色/绿色是神圣的,规避它不应该成为一种习惯。如果您不小心忘记删除该规避程序并假设所有测试都通过了怎么办?

您可以让它期望AssertionErrorException

@wip
@Test(expected=AssertionError.class)
public void wipTest() {
fail("work in progress");
}

在您的IDE中为此创建快捷方式应该不会太难。当然,我假设您在源代码中用注解标记测试。

我认为您的要求与JUnit的目的背道而驰,但我确实了解其用途。

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

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

关于unit-testing - 在JUnit4中将单元测试标记为预期的失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5889966/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com