我正在尝试使用 Tycho 为 Eclipse RCP 应用程序运行 jUnit 测试。
为此,我创建了一个简单的 jUnit 测试,当我单击 Run as > jUnit-Test 时运行。但是当我想用 mvn test 运行它时,它找不到 jUnit。
我在 Internet 上读到我必须将 jUnit 添加到 Build-Path。-> 我已经这样做了。此外,我读到我必须在我的 Manifest.mf 文件中添加 jUnit 作为 require-bundle。但是问题来了!!我收到错误:无法解决捆绑“org.junit”。
我的 MANIFEST.MF 文件如下所示:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests
Bundle-SymbolicName: myPackageName
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: myCompany
Fragment-Host: thePackageWhereTestesPluginIs
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.junit
我的错误在哪里?当我服用 org.junit4 时,它也无法解决......
谢谢!
更新:
现在我使用而不是require-bundle:
Import-package: org.junit4
(或 org.junit,其行为相同)并且可以在 manifest.mf 文件中解决。但是当我运行它时,出现以下错误: [ERROR] -> [Help 1] org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: org.osgi.framework.BundleException: Bundle myTestBundle cannot be解决了解决错误:Bundle myTestBundle - Missing Constraint: Import-Package: org.junit4; 版本="0.0.0"
我该如何解决这个问题?
谢谢!!
我的测试包的 pom 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>myProject.tycho.master</artifactId>
<groupId>myProject</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../myProject.tycho.master/pom.xml</relativePath>
</parent>
<groupId>myProject</groupId>
<artifactId>myProject.myTestBundle</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
</dependencies>
</project>
父pom:
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>myProject</groupId>
<artifactId>myProject.tycho.master</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho.version>0.17.0</tycho.version>
</properties>
<modules>
<module>../myProject.myTestBundle</module>
</modules>
<repositories>
<!-- configure p2 repository to resolve against -->
<repository>
<id>Repository1</id>
<layout>p2</layout>
<url>url-to-a-p2-site-on-my-server</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<resolver>p2</resolver>
<pomDependencies>consider</pomDependencies>
<target>
<artifact>
<groupId>myGroupId</groupId>
<artifactId>myGroupId.target</artifactId>
<classifier>targetPlatform</classifier>
</artifact>
</target>
<environments>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
</environments>
<ignoreTychoRepositories>false</ignoreTychoRepositories>
</configuration>
</plugin>
</plugins>
</build>
</project>
更新:我想我解决了这个问题!我将 jUnit 添加到我的 p2 更新站点,现在我没有收到任何错误!