gpt4 book ai didi

android - Maven 无法在 cloudbees 上运行单元测试

转载 作者:行者123 更新时间:2023-11-30 03:28:22 24 4
gpt4 key购买 nike

我有一个基于 Maven 的 Android 项目设置,用于 cloudbees 上的 ci。我的 Jenkins 工作只是在从 BitBucket 检索 src 后运行“安装”目标。一切都很好。唯一的问题是单元测试无法运行。

在 IntelliJ(本地)中运行完全相同的目标会找到并运行单元测试。

我的 pom 看起来像这样 -->

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.odl</groupId>
<artifactId>GhostRunner</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>GhostRunner</name>

<properties>
<platform.version> 4.1.1.4
</platform.version>
</properties>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.robolectric</groupId>
<artifactId>robolectric</artifactId>
<version>2.0-alpha-1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-android</artifactId>
<version>4.45</version>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-core</artifactId>
<version>4.45</version>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-jdbc</artifactId>
<version>4.45</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.4</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<platform>16</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
</plugin>
</plugins>
</build>
</project>

jenkins 的输出是这样的 -->

[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ GhostRunner ---
[INFO] No tests to run.
mojoSucceeded org.apache.maven.plugins:maven-surefire-plugin:2.15(default-test)
[JENKINS] Recording test results
mojoStarted com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.6.0(default-emma)

另一个有趣的地方是,我可以删除 surefire 依赖项,并且单元测试仍然可以针对 IntelliJ 中的安装目标正常运行。出于某种原因,Maven 在 Cloudbees 上从 Jenkins 运行时没有看到测试。

智慧得到感恩。

这是 cloudbees 不得不说的::

The issue here is that IntelliJ is compiling the test classes for you and putting those classes into the ${project.build.testOutputDirectory} for you.

You can replicate this failure locally by getting IntelliJ to execute clean install (hold ⌘ while clicking on the lifecycle goals)

There are two ways to solve this problem.

Tell Maven that your test sources are not in the standard place

Put your test sources into the standard place.

When you are dealing with lots of plugins, some of which not written by the Apache Maven team or the Codehaus Mojo team, going with the standard directory layout is the best way. Plugins subject to the review of the Apache Maven or Codehaus Mojo communities will usually pick up the changes when you tell Maven that you are using a non-standard layout. Plugins not subject to that review process can often not be aware of how to work correctly and as such you end up forced to align with the standard layout.

Stephen Connolly CloudBees, Inc

我已经重新组织了我的项目以反射(reflect) Maven 规范,但它仍然没有在 cloudbees 服务器上运行测试。

这是 jenkins 控制台输出的相关输出::

[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ GhostRunner ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /scratch/jenkins/workspace/ghost runner/src/test/resources
mojoSucceeded org.apache.maven.plugins:maven-resources-plugin:2.6(default-testResources)
mojoStarted org.apache.maven.plugins:maven-compiler-plugin:3.0(default-testCompile)
[INFO] No sources to compile
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ GhostRunner ---
mojoSucceeded org.apache.maven.plugins:maven-compiler-plugin:3.0(default-testCompile)
mojoStarted org.apache.maven.plugins:maven-surefire-plugin:2.15(default-test)
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ GhostRunner ---
[INFO] No tests to run.

我想最重要的一点是

No sources to compile

不知何故它仍然不知道测试在哪里。

最佳答案

根据您在上述问题中的评论,您似乎没有将测试源文件放入 Maven 期望的目录结构中。这实际上是 Maven 配置问题,与 CloudBees 没有直接关系(除了 CloudBees 使用 vanilla maven 来运行您的构建)。如果您尝试通过 maven 'mvn' 命令在本地运行您自己的构建(就像 CloudBees Jenkins CI 作业所做的那样),您应该会遇到同样的错误。

基于standard Maven directory structure ,您应该将测试的源代码放在:src/test/java

如果您想要/需要更改默认的 maven 目录结构,通常可以在 pom.xml 中提供配置更改来设置这些。然而,许多人发现与maven作斗争只会带来更多的痛苦,并最终回到标准。

有关更多信息,请查看关于 how to change the default Maven tests directory 的这个 stackoverflow 线程.

关于android - Maven 无法在 cloudbees 上运行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17870376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com