ParameterizedTest 在 @Before 函数之前执行。

huangapple go评论68阅读模式
英文:

ParameterizedTest gets executed before @Before function

问题

@Before注解用于setUp函数之前执行,@ParameterizedTest注解用于执行参数化测试。以下是您提供的代码的翻译:

为什么参数化测试在setUp函数之前执行

@Before
public void setUp(){
    System.out.println("一些逻辑");
}

@ParameterizedTest
@CsvSource({"1997"})
void myTest(String arg) {
    System.out.println(arg);
}
英文:

why parameterized tests are executed before setUp function?

    @Before
    public void setUp(){
        System.out.println("some logic");
    }


    @ParameterizedTest
    @CsvSource({"1997"})
    void myTest(String arg) {
        System.out.println(arg);
    }

答案1

得分: 4

关于 @aeberhart 的评论,JUnit 5 中没有 @Before 注解,如果你正在使用它作为测试运行器的话。你需要使用 @BeforeAll,它与 JUnit 4 的 @BeforeClass 相同。

英文:

Relating to @aeberhart's comment, there is no @Before annotation in JUnit 5, if that's what you're using as a test runner. You need to use @BeforeAll, which in is the same as JUnit 4's @BeforeClass.

huangapple
  • 本文由 发表于 2020年8月2日 19:50:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63215641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定