首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PAX考试-@ not方法未调用

PAX考试-@ not方法未调用
EN

Stack Overflow用户
提问于 2014-03-02 16:32:21
回答 1查看 405关注 0票数 0

我试图设置PAX考试的测试,如下所示:

代码语言:javascript
运行
复制
@ExamReactorStrategy(PerMethod.class)
public class AbstractTest {

    @Configuration
    public Option[] config() {
        return options(
                junitBundles(),

                /* PAX Logging */
                mavenBundle("org.ops4j.pax.logging", "pax-logging-api", "1.7.2"),
                mavenBundle("org.ops4j.pax.logging", "pax-logging-service", "1.7.2"),

                /* Apache Felix Config Admin */
                mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.0"),

                /* Eclipse Gemini dependencies */
                mavenBundle().groupId("org.aopalliance").artifactId("com.springsource.org.aopalliance").versionAsInProject(),
                mavenBundle().groupId("org.springframework").artifactId("org.springframework.aop").versionAsInProject(),
                mavenBundle().groupId("org.springframework").artifactId("org.springframework.beans").versionAsInProject(),
                mavenBundle().groupId("org.springframework").artifactId("org.springframework.context").versionAsInProject(),
                mavenBundle().groupId("org.springframework").artifactId("org.springframework.core").versionAsInProject(),

                /* Eclipse Gemini */
                mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-core", GEMINI_VERSION),
                mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-extender", GEMINI_VERSION),
                mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-io", GEMINI_VERSION),

                /* Other bundles */;
    }

    @Before
    public void setUp() throws Exception {
        ....
    }

}


@RunWith(PaxExam.class)
public class MyTest extends AbstractTest {

    @Inject
    private MyObject myObject;

    @Test
    public void testOne() {
        ...
    }

}

由于某些原因,不调用带有@Before注释的方法。

谢谢你,Mickael

编辑:我使用的PAX考试依赖项是:

代码语言:javascript
运行
复制
<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-container-native</artifactId>
    <version>${pax.exam.version}</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-junit4</artifactId>
    <version>${pax.exam.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-link-mvn</artifactId>
    <version>${pax.exam.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.ops4j.pax.url</groupId>
    <artifactId>pax-url-aether</artifactId>
    <version>${url.version}</version>
    <scope>test</scope>
</dependency>

我使用PAX考试版本3.4.0。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-06 14:10:50

我已经建立了一个测试项目,而且效果很好。

我终于找到了导致这个问题的原因。在配置过程中,似乎停止了测试的执行。

我使用Eclipse 2.0.M02,在我的应用程序上下文中使用占位符。例如,我需要将数据源URL设置为属性。我想使用@Before方法来使用configuration服务为PID设置配置。

由于应用程序上下文是在配置期间加载的,而且此时PID还没有配置(因为还没有调用@Before方法),所以我从Spring中得到一个错误,这会导致PAX中止当前测试的执行。

因此,在我的例子中,我不能使用来自@Before方法的Configuration。

解决方案是使用pax- to cm模块,它允许在配置方法中与配置管理服务交互,如下所示:

代码语言:javascript
运行
复制
@Configuration
public static Option[] config() {
    return options(
            junitBundles(),

            /* PAX Logging */
            mavenBundle("org.ops4j.pax.logging", "pax-logging-api", "1.7.2"),
            mavenBundle("org.ops4j.pax.logging", "pax-logging-service", "1.7.2"),

            /* Apache Felix Config Admin */
            mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.0"),

            ConfigurationAdminOptions.newConfiguration("my.pid")
                .put("prop1", "value1")
                .put("prop2", "value2")
                .asOption(),

            /* Eclipse Gemini + dependencies */
            mavenBundle().groupId("org.aopalliance").artifactId("com.springsource.org.aopalliance").versionAsInProject(),
            mavenBundle().groupId("org.springframework").artifactId("org.springframework.aop").versionAsInProject(),
            mavenBundle().groupId("org.springframework").artifactId("org.springframework.beans").versionAsInProject(),
            mavenBundle().groupId("org.springframework").artifactId("org.springframework.context").versionAsInProject(),
            mavenBundle().groupId("org.springframework").artifactId("org.springframework.core").versionAsInProject(),
            mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-core", GEMINI_VERSION),
            mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-extender", GEMINI_VERSION),
            mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-io", GEMINI_VERSION),

            /* Other bundles */
            );
}

还需要在POM中添加pax- to cm依赖项(如果使用Maven):

代码语言:javascript
运行
复制
<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-cm</artifactId>
    <version>3.4.0</version>
    <scope>test</scope>
</dependency>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22130252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档