gpt4 book ai didi

Parameterized JUnit5 Test with all Classes with the same Baseclass(对具有相同基类的所有类进行参数化JUnit5测试)

转载 作者:bug小助手 更新时间:2023-10-27 21:12:42 30 4
gpt4 key购买 nike



I try to run some tests on all classes that extends the same baseclass like:

我尝试在扩展相同基类的所有类上运行一些测试,如下所示:


   classe Baseclass {
abstract int method();
}

class A extends Baseclass { int method(){...} }

class B extends Baseclass {int method() {..}}

class Testclass {
@ParameterizedTest
@ValueSource( classes={T extends Baseclass})
void test(Baseclass T){
assertStuff(T..)}}

The Testclass should execute the test method with class A and B.
When I add a Class C that extends BaseClass class C should automatically be tested to.
Is there a way to do this ?

TestClass应该执行A类和B类的测试方法。当我添加一个扩展BaseClass的C类时,C类应该自动测试为。有办法做到这一点吗?


更多回答
优秀答案推荐

Think that @Tag can help you . Just tag the Baseclass with a tag such as :

相信@Tag能帮到你。只需使用如下标记标记Baseclass:


@Tag("baseClassTest")
classe Baseclass {
abstract int method();
}

Then depending on how you run the test , you can specify you only want to run the tests with the tag baseClassTest meaning that to run all tests the extends Baseclass. So if a new test class that extends BaseClass is added , it also will be covered.

然后,根据您运行测试的方式,您可以指定您只想运行带有标记base ClassTest的测试,这意味着要运行所有测试,就需要扩展Baseclass。因此,如果添加了扩展BaseClass的新测试类,它也将被涵盖。



  • For IntelliJ IDEA , you can refer to this.

  • For Maven , you can refer to this.

  • For Gradle , you can refer to this


更多回答

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