@Before 我可以用它来初始化吗

@Before can I use it for initialization

在 pax exam 中,我希望某些东西对所有测试函数都是通用的。为此,我使用了@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 方法可以很容易地替换为 Option 以提供您的容器。

例如:

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

 wrappedBundle(mavenBundle("commons-dbcp", "commons-dbcp", "1.2.2"))