简体   繁体   English

github 工作流程:maven 测试由于缺少一些测试资源而失败,但在本地运行

[英]github workflows: maven tests fail when because of missing some test resources, but runs local

I spent hours to find out, why one of my junit tests runs local but not on the github workflow.我花了几个小时来找出为什么我的 junit 测试之一在本地运行,但不在 github 工作流程上运行。 The test which fails checks the existence of some files to do some configuration stuff.失败的测试检查是否存在一些文件来做一些配置工作。 I'm using the maven-resources-plugin to copy these files to a folder inside the target directory.我正在使用 maven-resources-plugin 将这些文件复制到目标目录内的文件夹中。 Here is my plugin setting of my pom.xml:这是我的 pom.xml 的插件设置:

<plugin>
    <!-- move some test resources to target -->
    <artifactId>maven-resources-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-resource-one</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${basedir}/target/test-dir</outputDirectory>
                <resources>
                    <resource>
                        <directory>${basedir}/test-files</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

The files are copied as expected and mvn clean test runs as expected, but not within a github workflow.文件按预期复制,并且mvn clean test按预期运行,但不在 github 工作流程中。

Here is my workflow definition:这是我的工作流程定义:

name: Sonar Scan
on:
  push:
    branches:
      - develop
      - feature*
      - master
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source
        uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v2.3.1
        with:
          distribution: 'adopt'
          java-version: '11'
      - name: Cache SonarCloud packages
        uses: actions/cache@v1
        with:
          path: ~/.sonar/cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar
      - name: Build and analyze
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=abckey

I guess this is a typically RTFM problem, but I didn't find anything.我想这是一个典型的 RTFM 问题,但我什么也没找到。

Any hints?有什么提示吗?

UPDATE:更新:

Just testet, mvn clean test fails on github workflow too!只是 testet, mvn clean test在 github 工作流程上也失败了!

You don't need to copy test resource files to target[/sub/dir] explicitely if you place them in src/test/resources[/sub/dir] the Maven Resources Plugin is bound to the process-resources and process-test-resources phases by default and hence does this for you without any declaration in the POM:如果将测试资源文件放在src/test/resources[/sub/dir] ,则不需要process-test-resources process-resources资源文件显式复制到target[/sub/dir] process-test-resources默认为阶段,因此无需在 POM 中进行任何声明即可为您执行此操作:

The Resources Plugin handles the copying of project resources to the output directory. Resources Plugin 处理将项目资源复制到 output 目录。 There are two different kinds of resources: main resources and test resources.有两种不同的资源:主要资源和测试资源。 The difference is that the main resources are the resources associated to the main source code while the test resources are associated to the test source code.区别在于主要资源是与主要源代码相关联的资源,而测试资源与测试源代码相关联。

Thus, this allows the separation of resources for the main source code and its unit tests.因此,这允许主要源代码及其单元测试的资源分离。

Not that this is the reason for your issue but I'd remove the declaration from the POM anyway.并不是这就是您的问题的原因,但无论如何我都会从 POM 中删除声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使 Maven 运行所有测试,即使有些测试失败 - Making Maven run all tests, even when some fail Maven使用关键字“Test”运行所有测试 - Maven runs all tests with keyword “Test” Spock 测试用例在涉及异步客户端调用的多个测试时失败,但在单独运行时成功运行 - Spock test cases fail when multiple tests involved with async client calls , but runs successfully when individually run Maven测试在CI环境中运行本地失败 - Maven test runs local fails in CI environment TestNG 测试在作为 Maven 测试运行时失败,但在作为 TestNG 套件运行时通过 - TestNG tests fail when ran as Maven Test, but pass when running as TestNG suite 单元测试仅在maven运行时失败 - Unit tests only fail when run by maven Maven运行代码时缺少SSL SNI - SSL SNI missing when maven runs the code 为什么当我从 jaxws-maven-plugin 生成 wsdl 类时,由于缺少 ProviderImpl,它们无法在运行时运行? - Why when I generate wsdl classes from jaxws-maven-plugin they fail to run at runtime because of missing ProviderImpl? 用于将测试分为单元测试和集成测试的Maven surefire配置失败 - Maven surefire configuration for separating test into unit and integration tests fail 运行Maven测试时未执行黄瓜测试 - Cucumber tests not executing when running maven test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM