Junit @在初始化之前,我可以使用它吗

Junit @在初始化之前,我可以使用它吗,junit,osgi,apache-karaf,karaf,pax-exam,Junit,Osgi,Apache Karaf,Karaf,Pax Exam,在pax考试中,我希望所有测试函数的某些内容都是通用的。为此,我使用了@Before,使用@Before方法的问题是,它将在每个测试方法之前被调用。有没有办法解决这个问题。pax考试中是否有一些注释可用于解决此问题 @Before public void init() throws Exception{ featuresService.installFeature("hibernate"); featuresService.installFeature("

在pax考试中,我希望所有测试函数的某些内容都是通用的。为此,我使用了@Before,使用@Before方法的问题是,它将在每个测试方法之前被调用。有没有办法解决这个问题。pax考试中是否有一些注释可用于解决此问题

@Before
    public void init() throws Exception{
        featuresService.installFeature("hibernate");
        featuresService.installFeature("hibernate-validator");
        bundleContext.installBundle("wrap:mvn:osgi/osgi/3.0.1").start();
        bundleContext.installBundle("wrap:mvn:javax.xml/xml/3.1.0").start();
        bundleContext.installBundle("wrap:mvn:commons-dbcp/commons-dbcp/1.2.2").start();
        bundleContext.installBundle("wrap:mvn:commons-pool/commons-pool/1.3").start();
        bundleContext.installBundle("wrap:mvn:commons-lang/commons-lang/2.3").start();
    }

现在不可能在PaxExam运行的测试中有这样的行为,但是您的
init
方法可以很容易地替换为
选项
,用于容器的配置

例如:

features(maven().groupId("org.apache.karaf.assemblies.features")
       .artifactId("enterprise").type("xml").classifier("features")
       .versionAsInProject(), "hibernate", "hibernate-validator")


现在不可能在PaxExam运行的测试中有这样的行为,但是您的
init
方法可以很容易地替换为
选项
,用于容器的配置

例如:

features(maven().groupId("org.apache.karaf.assemblies.features")
       .artifactId("enterprise").type("xml").classifier("features")
       .versionAsInProject(), "hibernate", "hibernate-validator")


实际上这是一种可能的方法,但是Jérémie给出的解决方案是一个更好的解决方案。也许这个示例也会有所帮助:实际上这是一种可行的方法,但是Jérémie给出的解决方案是一个更好的解决方案。也许这个示例也会有所帮助: