2

有没有人尝试过使用 Bndtools 运行 PaxExam Junit 测试并可以给我一些建议?我自己试过了,但是没有 Maven,下载所有依赖项很痛苦。

到目前为止我所做的:

  1. 从 Central Maven 下载 PaxExam 依赖项(还有更简单的方法吗?)
  2. 在 cnf/bnd.bnd 中创建包含所有依赖项的属性
  3. 将属性添加到我要编写测试的 buildpath
  4. 执行测试失败,因为缺少更多依赖项,所以回到 1。:D

我想使用 PaxExam,因为它们只生成测试报告,但它们并不是真正的“Junit 测试”,因此更容易将 Ant Junit 任务用作 Bndtools 的集成测试。

后期场景:

  1. 与 Hudson 和 Ant 建立项目
  2. Hudson 还应该执行 Junit Ant Task,其中失败的测试也应该停止构建过程

上面的场景已经可以在没有运行 OSGi 环境的情况下使用普通的 Junit4 测试,但现在我想做集成测试。

有人能帮我吗?

问候。

4

1 回答 1

4

即使您不使用 Maven 来构建项目,您仍然可以使用它来下载 maven-artifacts 及其传递依赖项。为此,您首先必须安装 Maven。然后,您创建一个空目录,并在该目录中创建一个名为pom.xml. 对于 Pax Exam,这应该如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <exam.version>2.5.0</exam.version>
        <url.version>1.4.2</url.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-container-native</artifactId>
            <version>${exam.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-junit4</artifactId>
            <version>${exam.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-link-mvn</artifactId>
            <version>${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>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.framework</artifactId>
            <version>3.2.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>0.9.29</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>0.9.29</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

我从Pax Exam 文档中获取了依赖项列表。然后,您打开命令行,导航到您创建的目录pom.xml,然后执行以下命令:

mvn dependencies:copy-dependencies

(这假设您已经安装了 Maven,因此该命令mvn可从命令行使用)。现在 maven 将获取您在 中指定的依赖项的所有传递依赖项pom.xml,并默认将它们存储在其中target/dependency

于 2012-08-01T09:52:32.730 回答