当前位置: 首页 > 面试题库 >

Jenkins集成用于dotnet测试

侯兴为
2023-03-14
问题内容

我正在使用dotnet测试对dotnet核心库进行单元测试。我像这样在我的詹金斯奴隶上进行测试。

dotnet test test/Turbine.Domain.UnitTest -xml mstest-reports/Turbine.Domain.UnitTest.xml

测试报告如下所示。

<?xml version="1.0" encoding="utf-8"?>
<assemblies>
  <assembly name="Turbine.Domain.UnitTest.dll" environment="64-bit .NET (unknown version) [collection-per-class, parallel (8 threads)]" test-framework="xUnit.net 2.1.0.3179" run-date="2017-04-07" run-time="13:34:31" total="31" passed="31" failed="0" skipped="0" time="0.170" errors="0">
    <errors />
    <collection total="3" passed="3" failed="0" skipped="0" name="Test collection for Turbine.Domain.Tests.AccumulatePositionsTests" time="0.052">
      <test name="Turbine.Domain.Tests.AccumulatePositionsTests.CanAccumulatePositionsByPortfolioIndex" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="CanAccumulatePositionsByPortfolioIndex" time="0.0402475" result="Pass" />
      <test name="Turbine.Domain.Tests.AccumulatePositionsTests.LotEventsTriggerPositionEventsImmediately" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="LotEventsTriggerPositionEventsImmediately" time="0.0102925" result="Pass" />
      <test name="Turbine.Domain.Tests.AccumulatePositionsTests.CanAccumulatePositionsByDefaultIndex" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="CanAccumulatePositionsByDefaultIndex" time="0.0012357" result="Pass" />
    </collection>
    <collection total="4" passed="4" failed="0" skipped="0" name="Test collection for Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" time="0.087">
      <test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.MarketValueHandlesNegativeAmounts" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="MarketValueHandlesNegativeAmounts" time="0.0826806" result="Pass" />
      <test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.CanProduceFirmSummaryFromSnapshot" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="CanProduceFirmSummaryFromSnapshot" time="0.0012097" result="Pass" />
      <test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.GrossMarketValueHandlesNegativeAmounts" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="GrossMarketValueHandlesNegativeAmounts" time="0.0020873" result="Pass" />
      <test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.FirmSummaryProducesOutputOnQuote" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="FirmSummaryProducesOutputOnQuote" time="0.0010767" result="Pass" />
    </collection>
etc...

archiveXUnit在詹金斯(Jenkins)工作DSL中使用一个块来尝试阅读报告。

archiveXUnit {
  msTest {
    pattern('**/mstest-reports/*.xml')
  }
}

詹金斯似乎看到了这份报告。

记录测试结果

[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing MSTest-Version N/A (default)
[xUnit] [INFO] - [MSTest-Version N/A (default)] - 1 test report file(s) were found with the pattern '**/mstest-reports/*.xml' relative to '/home/jenkins/workspace/routing/Turbine/build_Turbine' for the testing framework 'MSTest-Version N/A (default)'.
[xUnit] [INFO] - Check 'Failed Tests' threshold.
[xUnit] [INFO] - Check 'Skipped Tests' threshold.
[xUnit] [INFO] - Setting the build status to SUCCESS
[xUnit] [INFO] - Stopping recording.

但这不是解析结果并将其合并到报告中。我在Jenkins构建仪表板上看不到测试报告。

有任何想法吗?


问题答案:

您可以使用以下管道html" target="_blank">代码来运行和发布dotnet核心测试结果:

node {
stage 'Checkout'
    cleanWs()
    checkout scm

stage 'Build'
    bat "\"C:/Program Files/dotnet/dotnet.exe\" restore \"${workspace}/YourProject.sln\""
    bat "\"C:/Program Files/dotnet/dotnet.exe\" build \"${workspace}/YourProject.sln\""

stage 'UnitTests'
    bat returnStatus: true, script: "\"C:/Program Files/dotnet/dotnet.exe\" test \"${workspace}/YourProject.sln\" --logger \"trx;LogFileName=unit_tests.xml\" --no-build"
    step([$class: 'MSTestPublisher', testResultsFile:"**/unit_tests.xml", failOnError: true, keepLongStdio: true])
}

我已将我制作的一些示例上传到GitHub,供所有人使用和贡献,请随时查看:

https://github.com/avrum/JenkinsFileFor.NETCore

这些pipline jenkinsfile会将以下pipline模板添加到您的构建中:

詹金斯管道示例



 类似资料:
  • translated_page: https://github.com/PX4/Devguide/blob/master/en/test_and_ci/jenkins_ci.md translated_sha: 95b39d747851dd01c1fe5d36b24e59ec865e323e Jenkins CI Jenkins continuous integration server on S

  • 我们目前正在为我们的团队开发持续交付管道实施。我们的方法是从Jenkins推送可部署到Nexus,然后使用Automic从Nexus拉取以部署到我们的目标环境。这的主要原因是目前自动部署是自动化的和到位的。我们只想重用现有的部署过程,并将其与我们正在编写的新CD Pipeline脚本集成。 我们面临的挑战是詹金斯的反向握手- 我们目前的做法 > JenkinsPipeline Script使用一个

  • 我试图使用jenkins和jenkins kubernetes插件为我的kubernetes集群建立一个测试框架。 我可以让jenkins提供pod并运行基本的单元测试,但不清楚的是我如何运行涉及多个pod之间协调的测试。 从本质上讲,我想做这样的事情: 我有两个主要问题: > < li> Pod生命周期:一旦podtemplate之后的块被清除,Pod就会终止。有没有一种公认的方法可以让豆荚一直

  • 现在我们有一个项目,包含两个工作。1) 是带有单元测试的标准构建。2) 是集成测试。它们是这样工作的: 构建整个项目,运行单元测试,启动集成测试工作 问题是步骤2)现在需要一个多小时才能运行,我想将集成测试并行化,以便它们花费更少的时间。但我不确定我该怎么做。我的第一个想法是,我可以有两个这样的步骤: 构建整个项目,运行单元测试,启动集成测试工作 构建整个项目,将其部署到integration s

  • 问题内容: 我使用kubeadm Kubernetes 1.9 RBAC集群进行了自举,并开始在基于jenkins / jenkins:lts的POD Jenkins内部。我想尝试https://github.com/jenkinsci/kubernetes- plugin 。我已经基于https://gist.github.com/lachie83/17c1fff4eb58cf75c5fb11a