- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
JetBrains 集成到 ReSharper Ultimate 中的 dotCover 客户端工具包含一个选项,用于获取在 IIS 下运行的应用程序(例如 ASP.NET MVC 应用程序)的代码覆盖率。
JetBrains 的 TeamCity 持续集成系统包含集成到其中的免费命令行版本 dotCover。 VSTest 运行程序可以很好地使用 dotCover 生成单元测试的代码覆盖率。但是,它不会生成在 IIS 下运行的代码的任何代码覆盖率,例如使用 Selenium WebDriver 之类的集成测试。
有没有办法使用 TeamCity 中的 dotCover 命令行工具来获取在 IIS 下运行的应用程序的代码覆盖率?
最佳答案
尚未实现使用 dotCover 命令行对 IIS 进行代码覆盖,如 this ticket 中所述。在 dotCover 问题跟踪器上。
但是,使用 a comment by Tony Fabris on the ticket 中的提示,我能够创建一个 Powershell 脚本,它可以生成应用程序的代码覆盖率。这使用 IIS Express 而不是 IIS,这并不理想,但目前已经足够接近了。
我已将我的脚本发布在这里,以防对其他人有用。
# This script runs our web-based tests, running IISExpress via TeamCity's
# dotCover, then runing the tests (also in dotCover) and then importing the
# test results and coverage results back into TeamCity.
# Note that some of the following is based on the comments by Tony Fabris on
# 20th Jan 2016 from here: https://youtrack.jetbrains.com/issue/DCVR-5921
# Configuration.
# The path to IIS Express.
$IISExpressPath = "C:\Program Files (x86)\IIS Express\IISExpress.exe"
# The path to dotCover, the TeamCity tool for .NET code coverage.
$DotCoverPath = "C:\TeamCity\buildAgent\tools\dotCover\dotcover.exe"
# The path to the VSTest console.
$VSTestConsolePath = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
# The path to PSExec.
$PSExecPath = "C:\path\to\PSTools\PSExec.exe"
# The path of the website which will be hosted in IIS express.
$WebsitePath = "C:\path\to\webapp"
# The port on which to host the website.
$WebsitePort = 12345
# The path to use as the working directory when running the tests.
# Note that the test results are written to a .trx file in a TestResults
# subdirectory of this directory.
$TestWorkingPath = "c:\path\to\checkout\dir"
# The assembly to run tests for.
$TestAssembly = "C:\path\to\test.dll"
# Get the TEMP folder.
# When run from the command-line, this will be something like the user's AppData\Local\Temp
# When run from TeamCity, this will be something like C:\TeamCity\buildAgent\temp\buildTemp
$tempDir = (Get-Item $Env:TEMP).FullName
Write-Host ("tempDir: " + $tempDir)
# Work out the output directory to write various output files to, in a
# CustomCoverage subdirectory of the temporary directory.
$outputDir = Join-Path $tempDir "CustomCoverage"
Write-Host ("outputDir: " + $outputDir)
# Create that output directory, but only if it doesn't exist.
if (!(Test-Path $outputDir))
{
md $outputDir
}
# Work out the path of the dotcover log file used for IISExpress, and delete it
# if it already exists.
$dotCoverIISExpressLogFilename = "$outputDir\dotcover.iisexpress.log.txt"
If (Test-Path $dotCoverIISExpressLogFilename)
{
del $dotCoverIISExpressLogFilename
}
# Work out the path of the dotCover output file used for IISExpress.
$dotCoverIISExpressOutputFilename = "$outputDir\dotcover.iisexpress.dcvr"
# Work out the arguments that we'll pass to IIS Express.
$IISExpressArgs = "/path:$WebsitePath /port:$WebsitePort /trace:info"
# Work out the arguments to pass to dotCover to start and cover IIS Express.
# Because the arguments to dotCover are long, we write them out to a config file.
$dotCoverIISExpressConfigFilename = "$outputDir\dotcover.iisexpress.config.xml"
"<?xml version=`"1.0`" encoding=`"us-ascii`"?>`n" + `
"<CoverageParams>`n" + `
" <LogFile>$dotCoverIISExpressLogFilename</LogFile>`n" + `
" <Output>$dotCoverIISExpressOutputFilename</Output>`n" + `
" <TargetExecutable>$IISExpressPath</TargetExecutable>`n" + `
" <TargetArguments>$IISExpressArgs</TargetArguments>`n" + `
"</CoverageParams>`n" `
| Out-File -Encoding ASCII $dotCoverIISExpressConfigFilename
# Write the command to execute dotCover out to a .bat file.
# Within the batch file we redirect stdout and stderr to a file, so we can see
# any reasons for failure.
# We put this in a batch file because it is too long for PSExec, which is
# limited to 260 characters for a single argument.
# http://forum.sysinternals.com/psexec-argument-to-long_topic14203.html
$dotCoverIISExpressRunFilename = "$outputDir\dotcover.iisexpress.run.bat"
"`"$DotCoverPath`" cover `"$dotCoverIISExpressConfigFilename`" > `"$outputDir\iisexpress.stdout.txt`" 2> `"$outputDir\iisexpress.stderr.txt`"" | Out-File -Encoding ASCII $dotCoverIISExpressRunFilename
# We need to run IISExpress (hosted in dotCover) in an interactive session, in
# order to be able to send it a WM_QUIT to shut it down gracefully after the
# tests (or else no coverage data will be recorded).
# We do this by running dotCover via PSExec.
# -i : interactive session
# -h : use the account's elevated token
# -accepteula : accept the pstools EULA, as the user running the build agent probably won't have
$psExecArgs = "-i -h -accepteula `"$dotCoverIISExpressRunFilename`""
# Start PSExec -> DotCover -> IISExpress.
# This will block, so we use Start-Process so that's it's done in a separate
# process, and so this script will continue.
# The -PassThru argument is required so that Start-Process will return a process
# handle.
$IISExpressProcess = (Start-Process $PSExecPath $psExecArgs -PassThru)
# Work out the path of the dotcover log file used for VSTest, and delete it
# if it already exists.
$dotCoverVSTestLogFilename = "$outputDir\dotcover.vstest.log.txt"
If (Test-Path $dotCoverVSTestLogFilename)
{
del $dotCoverVSTestLogFilename
}
# Work out the path of the dotCover output file used for VSTest.
$dotCoverVSTestOutputFilename = "$outputDir\dotcover.vstest.dcvr"
# Work out the arguments to pass to VSTest console.
# The /Logger:trx argument outputs the results in MSTest format, which TeamCity
# is able to import.
$vsTestArgs = "`"$TestAssembly`" /Logger:trx"
# Then run dotCover to run VSTest.
# This will run the tests, and also collect code coverage for the tests
# themselves.
# We expect the tests to be making calls to the website, which is running on IIS
# Express and being covered that way.
& $DotCoverPath cover /LogFile="$dotCoverVSTestLogFilename" /Output="$dotCoverVSTestOutputFilename" /TargetExecutable="$VSTestConsolePath" /WorkingDir="$TestWorkingPath" /TargetArguments="$vsTestArgs"
# We now need to shut down IISExpress.
# This has to be done gracefully, or else coverage data won't be collected.
# The core command to do this is 'taskkill /IM IISExpress.exe'.
# Note that there's no /F parameter to force - so what this will do is send a
# WM_QUIT to the process, to tell it to shut down.
# However, this only works if IISExpress was run in an interactive session (-i),
# and also if this taskkill call is as well.
# Both also require the -h parameter (elevated token) to be able to work.
# Note that we also want to log the output of taskkill, to help track down any
# issues.
# If we just do this, then powershell handles the redirection to the file:
# & PSExec taskkill > output.txt
# If we add a ` to escape the >, then powershell doesn't do the redirection, but
# we still end up redirecting the output of PSExec, instead of the output of
# taskkill.
# & PSExec taskkill `> output.txt
# Using 'cmd /C' instead allows us to pass the command in quotes, and therefore
# the redirect applies to the taskkill, instead of to the PSExec:
# & PSExec cmd / C "taskkill `> output.txt"
# We log the output of stdout (via >) and stderr (via 2>).
# So stop IIS Express.
& $PSExecPath -i -h -accepteula cmd /C `"taskkill /IM IISExpress.exe `> "$outputDir\taskkill.stdout.txt" 2`> "$outputDir\taskkill.stderr.txt"`"
# As a record, write out the contents of the stdout and stderr log files, for
# both IIS Express and taskkill, to help track down any issues.
# Note that IIS Express will have been logging during execution of the tests, so
# we can't collect the log until we've killed it.
Write-Host "-- iis express stdout --"
Get-Content "$outputDir\iisexpress.stdout.txt"
Write-Host "------------------------"
Write-Host "-- iis express stderr --"
Get-Content "$outputDir\iisexpress.stderr.txt"
Write-Host "------------------------"
Write-Host "-- taskkill stdout -----"
Get-Content "$outputDir\taskkill.stdout.txt"
Write-Host "------------------------"
Write-Host "-- taskkill stderr -----"
Get-Content "$outputDir\taskkill.stderr.txt"
Write-Host "------------------------"
# IIS Express takes a little while to close, the dotCover which is wrapping it
# then takes a little while to write out the results. This is all wrapped up in
# PSExec. Wait for this chain of processes to exit.
Write-Host "Waiting for IIS Express to close..."
$IISExpressProcess.WaitForExit()
Write-Host "- done"
# Import the test results in the .trx file in MSTest format.
# Note that this path is relative to the checkout directory, and that VSTest
# writes the output into the TestResults subdirectory of the working directory
# it was invoked with.
Write-Host "##teamcity[importData type='mstest' path='TestResults\*.trx']"
# These commands create an XML report from the dotCover coverage files.
# This isn't necessary, as TeamCity will handle merging the coverage files and
# then generating the report.
# However it may be useful to uncomment these for testing.
#& $DotCoverPath report /Source:$dotCoverIISExpressOutputFilename /Output:$outputDir\dotcover.iisexpress.report.xml /ReportType:xml
#& $DotCoverPath report /Source:$dotCoverVSTestOutputFilename /Output:$outputDir\dotcover.vstest.report.xml /ReportType:xml
# Write a service message to make TeamCity import code coverage from IIS express.
# Note that TeamCity will delete this file once it has processed it.
Write-Host "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='$dotCoverIISExpressOutputFilename']"
# Write a service message to make TeamCity import code coverage from VSTest.Console.
# Note that TeamCity will delete this file once it has processed it.
Write-Host "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='$dotCoverVSTestOutputFilename']"
请注意,在我的例子中,我 checkout 到固定目录,因此网站、工作路径和测试程序集都位于已知的绝对路径。 TeamCity 默认设置是为每个构建 checkout 到不同的临时目录,因此如果您使用默认设置,则需要更改脚本以考虑到这一点。
关于iis - 使用 dotCover 命令行的 IIS 代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36052778/
当我查看 IIS 日志文件时,我可以在一天中的不同时间看到标题行被写入日志文件。我唯一一次看到这种情况发生是在 IIS 重置时;或启动。 例如下面的标题行; #Software: Microsoft
有谁知道为什么以下 web.conig 更改不起作用: 在我添加 javascript 文件后仍然没有被压缩(gzip)。我折腾了几天,因为一开始我真的不知道问题是
目前,我们所有的网络应用程序都将其应用程序池标识设置为 ApplicationPoolIdentity。现在,当一个应用程序需要访问某些服务器上的某些资源时,比如添加/读取某些文件,该应用程序会在代码
在 IIS(特别是 6.0)中,在“主目录”选项卡下,如果我更改本地路径,是否会导致 IIS 重新启动或应用程序池回收? 相关的,是否有概述 IIS 元数据库的哪些更改将触发重新启动或应用程序池回收的
只要更改了任何 web.config 文件,AFAIK IIS 就会重新启动。 我创建了自己的配置文件(my.config,层次结构略有不同)。是否有可能让 IIS 自动(自动神奇地 :))重新启动,
你好, 我正在寻找 IIS 日志中列出的浏览器条目列表,以帮助识别访问我们网站的不同版本的浏览器。也许没有一个列表,而是一个应该用来识别不同浏览器及其版本的算法。 请注意,我不是在寻找日志分析器,而是
我想知道上次重新启动 iis 是什么时候。 IIS 是否保留了此日志,我在哪里可以找到此日志? 谢谢 最佳答案 打开事件查看器,导航到“Windows 日志”->“系统” 在右侧的“操作” Pane
在全新安装的带有 IIS 7 的 Windows Server 2008 R2 上,它会在 C:\inetpub\wwwroot 中创建一个默认网站。 .我确信对于存储网站文件的好位置有很多主观意见,
我已按照 this question 中的说明在 IIS 中实现动态内容压缩。 . 当我发送请求时,我看不到响应被 gzip 压缩的任何证据: IIS版本为7.5 有什么明显的我应该检查以解决此问题吗
这是场景: 服务器 A 托管“主”应用程序 (www.example.com) 服务器 B 托管支持应用程序 (b.example.com) 它们通过 192.* 地址在内部相互连接,并且都可以通过
是否有任何替代 IIS 管理 UI 可用于从程序重置 IIS?.. 现在我们已经创建了一个批处理文件,如果 iis 重置并每小时安排一次...... 我只是想要一些东西,这样我们就不能重置 iis..
我的 Windows Server 在 IIS 7.5 上运行 Web 应用程序。 我想知道为什么 IIS 应用程序池使用大量内存。 请参阅我从服务器捕获的屏幕截图。 在名为 TEST 2.0(.NE
我在 IIS 7.5 上运行的 ASP Classic 站点上收到服务器错误。 我将“向浏览器发送错误”设置为 True ,但是我仍然收到以下错误屏幕: 最佳答案 IIS 正在劫持您的经典 ASP 应
我正在尝试通过IIS上的反向代理连接到websockets服务器(websockify)。 IIS和Websockets服务器位于同一台物理服务器上(Windows Server 2012 R2,II
我需要让我的开发机器从本地机器商店读取证书 为此,我需要运行winhttpcertcfg.exe并指定我要提升的帐户 该帐户用于IIS表示什么? (对于IIS,它将是IWAM_MachineName)
我正在阅读特定命令(SET-WEBCONFIGURATIONPROPERTY),但出现"is not recognized as a cmdlet"错误。给我的建议是,即使我使用的是SharePoin
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我已经从官方镜像(https://hub.docker.com/r/microsoft/iis/)运行了IIS 在Windows Server 2016上 有什么方法可以从IIS管理器连接到该IIS,
你好, 如果 iis 未运行,我想编写一个状态为的代码。 最佳答案 从命令行启动 IIS: iisreset /start 从命令行停止 IIS: iisreset /stop 重新启动(停止和启动)
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我是一名优秀的程序员,十分优秀!