微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何让业力单元测试以 Cobertura 格式出现在 Jenkins 上

如何解决如何让业力单元测试以 Cobertura 格式出现在 Jenkins 上

我目前正在尝试为角度应用程序生成业力单元测试 Jenkins 管道。我正在使用 maven 构建和执行测试,但是,Jenkins 上没有记录任何测试,试图以 cobertura 报告格式查看它们。

Maven构建Pom.xml文件代码如下:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nassep</groupId>
<artifactId>karma-unit-tests</artifactId>
<version>0.0.1-SNAPSHOT</version>


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <junit.jupiter.version>5.5.2</junit.jupiter.version>
    <junit.platform.version>1.5.2</junit.platform.version>
    <!-- <jenkins.karmaTest.reportsDirectory>karma-results</jenkins.karmaTest.reportsDirectory> -->
</properties>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M5</version>
            <configuration>
                <trimstackTrace>false</trimstackTrace>
                <!-- <skipTests>true</skipTests> -->
            </configuration>
        </plugin>
    </plugins>
</reporting>

<build>
    <plugins>

        <plugin>
            <groupId>com.SEOvic.maven.plugins</groupId>
            <artifactId>npm-maven-plugin</artifactId>
            <version>1.0.4</version>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.0.0</version>

            <executions>
                <execution>
                    <id>npm install</id>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <phase>validate</phase>
                    <configuration>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                </execution>
                <execution>
                    <id>exec-npm-install (sep-deps) </id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>sep-structures/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (sep-structures)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>sep-structures/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>run</argument>
                            <argument>build-sep-structures</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (ext deps) </id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>ext-api-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (ext-api-kit)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>ext-api-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>run</argument>
                            <argument>build-ext-api-kit</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (node deps) </id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>node-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (node-kit)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>node-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>run</argument>
                            <argument>build-node-kit</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (cron deps)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>cron-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (cron-kit)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>cron-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>run</argument>
                            <argument>build-cron-kit</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (auth deps)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>auth-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (auth-kit)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>auth-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>run</argument>
                            <argument>build-auth-kit</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-install (ng deps)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>angular-kit/</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-bash-cp (angular-kit)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>angular-kit/</workingDirectory>
                        <executable>bash</executable>
                        <arguments>
                            <argument>-c</argument>
                            <argument>cp ./src/environments/environment.ts ./src/environments/environment.test.ts</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>

                <execution>
                    <id>exec-npm-install (angular-kit)</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>angular-kit/</workingDirectory>
                        <executable>./node_modules/@angular/cli/bin/ng</executable>
                        <arguments>
                            <argument>test</argument>
                            <argument>--watch=false</argument>
                        </arguments>
                        <successCodes>
                            <successCode>0</successCode>
                            <successCode>1</successCode>
                          </successCodes>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>  
            </executions>
        </plugin>

        <plugin>
            <groupId>com.kelveden</groupId>
            <artifactId>maven-karma-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>start</goal>
                    </goals>
                    <!-- <configuration> -->
                    <!-- <arguments>run test</arguments> -->
                    <!-- </configuration>     -->
                </execution>
            </executions>
            <configuration>
                <karmaExecutable>angular-kit/node_modules/.bin/karma</karmaExecutable>
                <configFile>angular-kit/src/karma-jenkins.conf.js</configFile>
                <browsers>PhantomJS</browsers>
                <autoWatch>false</autoWatch>
                <singleRun>true</singleRun>
                <colors>true</colors>
                <skipKarma>false</skipKarma>
                <skipTests>false</skipTests>
                <karmaFailureIgnore>true</karmaFailureIgnore>
            </configuration>
        </plugin>
    </plugins>
</build>

karma 配置文件(karma-jenkins.conf.js)文件如下:

module.exports = function (config) {
config.set({
    basePath: '..',frameworks: ['jasmine'],files: [],exclude: [
        "node_modules","**/*.spec.ts","**/*.module.ts","**/*.namespace.ts",],preprocessors: {
        '**/*.ts': ['coverage'],'**/!(*.spec).ts': ['coverage'],//<-- Ignore
        '**/!(*.module).ts': ['coverage'],//<-- Ignore
        '**/!(*.namespace).ts': ['coverage'],//<-- Ignore
    },mime: {
        'text/x-typescript': ['ts','tsx']
    },// added `junit`
    reporters: ['progress','junit','coverage'],port: 9876,colors: true,logLevel: config.LOG_INFO,// don't watch for file change
    autoWatch: false,// only runs on headless browser
    browsers: ['PhantomJS'],// just run one time
    singleRun: true,// remove `karma-chrome-launcher` because we will be running on headless
    // browser on Jenkins
    plugins: [
        'karma-jasmine','karma-phantomjs-launcher','karma-junit-reporter','karma-coverage'
        
    ],// changes type to `cobertura`
    coverageReporter: {
        type: 'cobertura',dir: 'target/coverage-reports/'
    },// saves report at `target/surefire-reports/TEST-*.xml` because Jenkins
    // looks for this location and file prefix by default.
    junitReporter: {
        outputFile: 'target/surefire-reports/TEST-jconf-karma-results.xml',suite: 'angular-toolkit',usebrowserName: false,nameFormatter: undefined,classNameFormatter: undefined,properties: {},xmlVersion: null
    }
});

};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。