Java 如何将方法添加到JUNIT测试套件。。?

Java 如何将方法添加到JUNIT测试套件。。?,java,junit,annotations,Java,Junit,Annotations,我正在为我的测试用例集创建自定义注释,我只想选择那些符合注释标准的方法,并动态创建测试套件 有没有办法将方法添加到测试套件而不是整个类 差不多 @Suite.Suitemethods({ Support.method1(), Test2.method2(), ServiceName.method3(), ServiceName2.method4() })使用类别功能 样本: 申报测试服: interface Cate1{}; @RunWith(Categories.class) @Incl

我正在为我的测试用例集创建自定义注释,我只想选择那些符合注释标准的方法,并动态创建测试套件

有没有办法将方法添加到测试套件而不是整个类

差不多

@Suite.Suitemethods({
Support.method1(),
Test2.method2(),
ServiceName.method3(),
ServiceName2.method4()

})

使用类别功能

样本: 申报测试服:

interface Cate1{};

@RunWith(Categories.class)  
@IncludeCategory(Cate1.class)//Only allow @Category(Cate1.class)  
@SuiteClasses({Support.class,   
               Test2.class,
               ServiceName.class,...}) 
class MyTest{}
在测试用例中,只有m1()将运行:

class Support{
    @Test   
    @Category(Cate1.class)  
    public void m1(){}  

    @Test  
    public void m2(){}  

}

@盛源,用户想说的是什么

  Class A{

    @Test     
    @CustomAnnotation(attrib1 = "foo"; attrib2 = "moo"; attrib3 = "poo") 
    void methodA(){ }

    @Test      
    @CustomAnnotation(attrib1 = "blahblah"; attrib2 = "flahflah"; attrib3 = "klahklah") 
    void methodB(){ }

    @Test      
    @CustomAnnotation(attrib1 = "foo"; attrib2 = "flahflah"; attrib3 = "poo") 
    void methodC(){ }
    }
现在,使用reflections,我的注释处理类将返回一组/列表符合我的条件的方法(比如attrib1=“foo”)。 方法A和方法C将满足要求。现在我需要在运行时将它们添加到测试套件中并运行它

如何将它们添加到测试套件中? 你所建议的显然是编译时解决方案。 用户需要一个运行时解决方案。在给出标准之前,用户不知道哪些方法将成为测试套件的一部分

我也在为JUNIT4寻找同样的解决方案。 我想这在Junit3是可能的。不过我不确定。如果您遇到此用例的解决方案,请告知我们