我正在开发Eclipse RCP。我将Jenkins用作CI服务器,用于构建系统并运行单元测试。我可以从Eclipse IDE中运行我的单元测试,没有任何问题,但是当Jenkins尝试在构建作业中执行相同的操作时,出现以下错误消息:

[INFO] --- maven-surefire-plugin:2.18.1:test (test) @ net.morcate.console.scripting ---
[INFO] Surefire report directory: /var/lib/jenkins/jobs/Console-Devel/workspace/sssb-console/net.morcate.console.scripting/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Running net.morcate.console.scripting.views.browser.FileServerStatusListenerTest

Tests run: 10, Failures: 0, Errors: 10, Skipped: 0, Time elapsed: 1.353 sec <<< FAILURE! - in net.morcate.console.scripting.views.browser.FileServerStatusListenerTest
StatusChange_With_Status_INITIALIZING_Should_NOT_UpdateBrowser(net.morcate.console.scripting.views.browser.FileServerStatusListenerTest)  Time elapsed: 1.315 sec  <<< ERROR!
java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:263)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:240)
    at org.eclipse.swt.internal.C.<clinit>(C.java:21)
    at org.eclipse.swt.widgets.Display.<clinit>(Display.java:138)
    at sun.reflect.GeneratedSerializationConstructorAccessor7.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
    at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
    at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:111)
    at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:51)
    at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:54)
    at org.mockito.internal.MockitoCore.mock(MockitoCore.java:45)
    at org.mockito.Mockito.mock(Mockito.java:921)
    at org.mockito.internal.configuration.DefaultAnnotationEngine.processAnnotationOn(DefaultAnnotationEngine.java:61)
    at org.mockito.internal.configuration.DefaultAnnotationEngine.createMockFor(DefaultAnnotationEngine.java:36)
    at org.mockito.internal.configuration.DefaultAnnotationEngine.process(DefaultAnnotationEngine.java:85)
    at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:40)
    at org.mockito.MockitoAnnotations.scan(MockitoAnnotations.java:112)
    at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:95)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.withBefores(JUnit45AndHigherRunnerImpl.java:27)
    at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:268)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
    at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)


两台计算机均为Linux Ubuntu 14.04LTS-64位。因此,我的猜测是CI服务器中存在一些配置问题。



这是我在主pom文件中所拥有的,但是我在任何地方都没有说要用来运行单元测试的体系结构:

<plugin>
    <groupId>${tycho-groupid}</groupId>
    <artifactId>target-platform-configuration</artifactId>
    <version>${tycho-version}</version>
    <configuration>
        <target>
            <artifact>
                <groupId>scripts.console</groupId>
                <artifactId>net.morcate.console.target</artifactId>
                <version>1.0.0-SNAPSHOT</version>
                <!-- This is the target file to be used to build the console. -->
                <classifier>consoleTest</classifier>
            </artifact>
        </target>
        <resolver>p2</resolver>
        <environments>
            <environment>
                <os>win32</os>
                <ws>win32</ws>
                <arch>x86</arch>
            </environment>
            <environment>
                <os>win32</os>
                <ws>win32</ws>
                <arch>x86_64</arch>
            </environment>
            <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>solaris</os>
                <ws>gtk</ws>
                <arch>x86</arch>
            </environment>
            <environment>
                <os>solaris</os>
                <ws>gtk</ws>
                <arch>sparc</arch>
            </environment>
        </environments>
    </configuration>
</plugin>


如果更改了<environment>元素的顺序,并且我首先将其用于linux gtk x86_64,则按预期执行测试。所以问题是:如何设置环境以在pom文件中运行测试?

最佳答案

Tycho surefire测试运行时的环境来自(以递减的顺序)automatically derived


在Maven settings.xml中配置的属性,
系统属性,以及
在POM中配置的项目属性。


但是,似乎您没有使用tycho-surefire-plugin,但是您已经手动配置了maven-surefire-plugin来运行测试。

要解决此问题,您可能仅需要从POM中删除maven-surefire-plugin配置,并确保您使用的包装类型为eclipse-test-plugin。该包装类型自动包含使用Tycho的surefire插件执行的测试。

10-08 19:38