How do I show the Steps in a SpecFlow report using nunt 3? - bdd

The SpecFlow sample documentation has a show link next to the scenario which I assume shows the steps.
When I generate my report I don't have this link.
I runt the tests and generate the report as follows using Visual Studio 2017 and .NET Framework 4.6.2
%solution_root%packages\NUnit.ConsoleRunner.3.6.1\tools\nunit3-console.exe
--labels=All --out=output.txt "--result=output.xml;format=nunit2" SystemIntegration.Test.dll
%solution_root%packages\SpecFlow.2.1.0\tools\specflow.exe
nunitexecutionreport %project_file% /xmlTestResult:output.xml
/testOutput:output.txt /out:report.html

So, apparently the output.txtneeds to be in the nunit2 format as well but format=nunit2 does not work on that arg. To update the .txt file I added a powershell command to replace => with ***** in the output text file before running the execution report.
powershell -command "(get-content 'output.txt') | ForEach-Object { $_ -replace '=>', '*****' } | Set-Content 'output.txt'"
Note: this is fixed in SpecFlow code but not yet released. Will update this answer when fix is available.

Related

TFS Build Configuration - Nuget Publisher

We are using TFS and nexus package manager. For the CI we have Nuget Publisher task.
For the Path/Pattern to nupkg I wrote: "^((?!SNAPSHOT).)*nupkg;-:**/packages/^((?!SNAPSHOT).)*nupkg;-:^((?!SNAPSHOT).)*nupkg"
I want to say take nupkg files which do not contain SNAPSHOT in the file name.
1-C:_work\2\s\test-project.1.0.1-SNAPSHOT-umut.nupkg
2-C:_work\2\s\test-project.1.0.1.nupkg
I want to take the second file.
But when I start the build, I get the error:
Starting: NuGet Publisher
******************************************************************************
==============================================================================
Task : NuGet Publisher
Description : Deprecated: use the “NuGet” task instead. It works with the new Tool Installer framework so you can easily use new versions of NuGet without waiting for a task update, provides better support for authenticated feeds outside this account/collection, and uses NuGet 4 by default.
Version : 0.2.37
Author : Lawrence Gripper
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=627417)
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Error: No matching files were found with search pattern: C:\_work\2\s\**\*^((?!SNAPSHOT).)*nupkg;-:**\packages\**\*^((?!SNAPSHOT).)*nupkg;-:**\*^((?!SNAPSHOT).)*nupkg
Packages failed to publish
******************************************************************************
Finishing: NuGet Publisher
Path/Pattern to nupkg argument doesn't support ! wildcard, it supports:
You need to use powershell script to filter and publish the packages.
#TetraDev in this post provides a powershell script to bulk push NuGet packages to a VSTS feed. It will ignore any of the .symbols.nuget files:
set-location \\path\to\nugetpackages
$files=get-childitem | where {$_.Name -like "*.nupkg" -and $_.Name -notlike "*symbols*"}
foreach($file in $files) {
.\NuGet.exe push -Source "MySource" -ApiKey key $file.name
}

How to set assembly version to Jenkins build number?

I am using "Change Assembly Version" plug-in in Jenkins to update all AssemblyInfo.cs files of my ASP.NET MVC project to apply version number during build process. If I set the "Assembly Version" value to a hard-coded one, this works very well.
But my requirement is different - I would want to use a build number in the version number. For example, "1.1.0.25", where 25 is the build number and auto-generated by Jenkins. In short, the versions should be like "1.1.0.<>"
I could do this in TFS build process using TFS environment variables, I am new in Jenkins, and not sure how can we achieve this in Jenkins.
Following is a screenshot of "Change Assembly Version" plug-in from Jenkins for your quick reference:
Thanks in advance
The previous answer about how to use "Change Assembly Version" plugin for Jenkins doesn't work.
In my AssemblyInfo.cs files I usually set them up with auto incrementing version to help local dev work.
Example
AssemblyInfo.cs contains:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
After the Jenkins build if the version is 10 then AssemblyInfo.cs will contain:
[assembly: AssemblyVersion("1.0.10")]
[assembly: AssemblyFileVersion("1.0.10")]
The plugin is used like so to achieve the above:
Assembly Version: $BUILD_NUMBER
FileName:
RegexPattern: Assembly(\w*)Version\("(\d+).(\d+).(\*)"\)
ReplacementPattern: Assembly$1Version("$2.$3.%s")
One other error I got whilst using the plugin was the file permission didn't allow write access. In order to fix this find the AssemblyInfo.cs and disable "Read Only".
Hope to helps anyone.
For others looking to update just 1 number of the version number but keep the rest of the existing version numbers you can set up the "Change Assembly Version" plug-in as follows:
Assembly Version: $BUILD_NUMBER
FileName: <project folder>/Properties/AssemblyInfo.cs
RegexPattern: Assembly(\w*)Version\("(\d+).(\d+).(\d+).(\d+)"\)
ReplacementPattern: Assembly$1Version("$2.$3.%s")
This will keep the existing, first 2 numbers already contained in the Assembly???Version settings and set the 3rd version number to the current Jenkins build number.
Example
AssemblyInfo.cs contains:
[assembly: AssemblyVersion("1.40.0.0")]
[assembly: AssemblyFileVersion("1.40.0.0")]
If the Jenkins build number is 103, then after the above settings are used by the Change Assembly Version plugin the AssemblyInfo.cs will contain:
[assembly: AssemblyVersion("1.40.103.0")]
[assembly: AssemblyFileVersion("1.40.103.0")]
Note
If you are using subversion (and likely other source control systems) and are using the "Check-out Strategy" of "Use SVN update as much as possible" you will have to change it to "Use SVN update as much as possible with svn revert before update" to ensure that the modified AssemblyInfo.cs file is reset for the next build.
Cool, I found the answer myself.
basically, I had to give "1.0.0.$BUILD_NUMBER" in the "Assembly Version" field of the "Change Assembly Version" plugin
I had to do this recently without the "Change Assembly Version" plug-in. I just used a PowerShell script instead. I'll post it here as it may offer a bit more flexibility for those that want it:
if (Test-Path env:BUILD_NUMBER) {
Write-Host "Updating AssemblyVersion to $env:BUILD_NUMBER"
# Get the AssemblyInfo.cs
$assemblyInfo = Get-Content -Path .\MyShinyApplication\Properties\AssemblyInfo.cs
# Replace last digit of AssemblyVersion
$assemblyInfo = $assemblyInfo -replace
"^\[assembly: AssemblyVersion\(`"([0-9]+)\.([0-9]+)\.([0-9]+)\.[0-9]+`"\)]",
('[assembly: AssemblyVersion("$1.$2.$3.' + $env:BUILD_NUMBER + '")]')
Write-Host ($assemblyInfo -match '^\[assembly: AssemblyVersion')
# Replace last digit of AssemblyFileVersion
$assemblyInfo = $assemblyInfo -replace
"^\[assembly: AssemblyFileVersion\(`"([0-9]+)\.([0-9]+)\.([0-9]+)\.[0-9]+`"\)]",
('[assembly: AssemblyFileVersion("$1.$2.$3.' + $env:BUILD_NUMBER + '")]')
Write-Host ($assemblyInfo -match '^\[assembly: AssemblyFileVersion')
$assemblyInfo | Set-Content -Path .\MyShinyApplication\Properties\AssemblyInfo.cs -Encoding UTF8
} else {
Write-Warning "BUILD_NUMBER is not set."
}

grails - The requested resource is not available when adding new method to controller in interactive mode

I am new to Grails, learning about its basics. One of the first things I did was to follow the presentation on https://grails.org/learn. According to that it should be possible to add a new method to a controller while the application is running in interactive mode (launched by the run-app target), and access that method as an action without the need to restart the application.
When I was trying to do so, I got an error message 404 from the web server with the explanation: "The requested resource is not available". The new method does work fine after the application is restarted.
I am using:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"
$ java -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode)
$ grails -version
Grails version: 2.4.3
The steps I did:
$ grails create-app grailsapp
| Created Grails Application at /home/marci/grailsapp
$ cd grailsapp/
$ grails
| Daemon Started
grails> create-controller hello
| Compiling 10 source files
| Compiling 131 source files
| Created file grails-app/controllers/grailsapp/HelloController.groovy
| Created file grails-app/views/hello
| Created file test/unit/grailsapp/HelloControllerSpec.groovy
grails>
I implemented index() in grails-app/controllers/grailsapp/HelloController.groovy:
package grailsapp
class HelloController {
def index() {
render "index"
}
}
Saved the file, ran the app:
grails> run-app
| Running Grails application
| Server running. Browse to http://localhost:8080/grailsapp
| Application loaded in interactive mode. Type 'stop-app' to shutdown.
| Enter a script name to run. Use TAB for completion:
grails>
Checked http://localhost:8080/grailsapp/hello/index with the browser, worked fine.
Now I added another method:
package grailsapp
class HelloController {
def index() {
render "index"
}
def somemethod() {
render "somemethod"
}
}
Saved the file. Grails seems to have noticed the change in the source code and recompiled the file:
| Compiling 1 source files
| Compiling 1 source files.
| Compiling 1 source files..
| Compiling 1 source files...
| Compiling 1 source files....
| Compiling 1 source files.....
grails>
Now if I try to access the new method by the URL http://localhost:8080/grailsapp/hello/somemethod from the browser then Tomcat says:
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/7.0.55
Note that the message is empty. If I try to access a method that does not exist, I do get a message, therefore a different error. For example http://localhost:8080/grailsapp/hello/doesnotexist :
HTTP Status 404 - /grailsapp/hello/doesnotexist
type Status report
message /grailsapp/hello/doesnotexist
description The requested resource is not available.
Apache Tomcat/7.0.55
If I restart the application in interactive mode and try the somemethod action again, then it works fine.
grails> stop-app
| Server Stopped
grails> run-app
| Running Grails application
| Server running. Browse to http://localhost:8080/grailsapp
| Application loaded in interactive mode. Type 'stop-app' to shutdown.
| Enter a script name to run. Use TAB for completion:
grails>
Now http://localhost:8080/grailsapp/hello/somemethod return the response I expect.
My question is, should the new action be available without restart, as it is demonstrated in the presentation? Is this a bug in the release 2.4.3 of Grails? Or should I do something more to activate this feature?
Thanks in advance,
Marton
should the new action be available without restart, as it is
demonstrated in the presentation?
Yes.
Is this a bug in the release 2.4.3 of Grails?
Yes.
Or should I do something more to activate this feature?
No, you should not have to do something more.
The reloading agent should work when you are in interactive mode but apparently isn't. If you file an issue at https://jira.grails.org/browse/GRAILS we can take a look at that.
Thanks for the feedback.

"Required package rtl not found" when building with Hudson

I am trying to get Hudson to work with my Delphi project. I am using the following batch file to build my project (as suggested in this blog post):
call "C:\Program Files\Embarcadero\RAD Studio\8.0\bin\rsvars.bat"
msbuild /p:Win32LibraryPath="$(BDS)\lib;$(BDS)\lib\win32\release;$(BDS)\lib\win32\debug;$(BDSUSERDIR)\Imports;$(BDS)\Imports;$(BDSCOMMONDIR)\Dcp;$(BDS)\include;" /t:build /p:config=Debug /verbosity:detailed "MyProject\src\MyProject.dproj"
if errorlevel 1 exit 1
I always end up with the error
Embarcadero Delphi for Win32 compiler version 22.0
Copyright (c) 1983,2010 Embarcadero Technologies, Inc.
Fatal: E2202 Required package 'rtl' not found
I don't understand this as rtl.dcp is in "$(BDS)\lib\win32\release" which is on the library path. I am using runtime packages by the way.
Any hints what I can do to solve this?
Edit It seems that the paths do not end up in the command line, which looks something like (after removing project-specific paths):
C:\Program Files\Embarcadero\RAD Studio\8.0\bin\dcc32.exe -$O- -$W+ --inline:off -$A4 -$R+ -$Q+ --doc --no-config -B -LUrtl;vcl;ReportingR;ComponentsR -Q -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE -DDEBUG;CONSTRAINT_CHECKING;_VER6;EUREKALOG_VER6;EurekaLog -V -VN -GD --drc -W-SYMBOL_DEPRECATED -W-SYMBOL_PLATFORM -W-UNIT_PLATFORM -W-UNIT_DEPRECATED Myproject.dpr
I found the answer in a comment to the original blog post. It turns out that in Delphi XE they changed the name of the Win32LibraryPath property to DelphiWin32LibraryPath. Changing the batch script accordingly fixes the issue.
The first path $(BDS)\Lib for XE,XE2 and XE 10.2 should be change for $(BDSLIB)\$(PLATFORM)\release

Using gtest in jenkins

I successfully run my unit test with google test in Jenkins, but I don't know how to show the .xml file generated by gtest. It is said that gtest satisfies the JUnit format, so what I set is as follows:
But it ends up with errors after a building.
No test report files were found. Configuration error?
Build step 'Publish JUnit test result report' changed build result to FAILURE
Finished: FAILURE
Fraser's answer is good and you need some extra processing to convert the gtest XML to proper JTest format.
First you ask gtest to output the result to XML using:
mygtestapp --gtest_output=xml:gtestresults.xml
Then in a script you need to add extra elements to properly flag skipped tests as such. Jenkin's JTest processor requires that a skipped test contains the <skipped> element and not just setting status to "notrun":
awk '{ if ($1 == "<testcase" && match($0, "notrun")) print substr($0,0,length($0)-2) "><skipped/></testcase>"; else print $0;}' gtestresults.xml > gtestresults-skipped.xml
mv gtestresults.xml gtestresults.off
If running this on a windows batch file, put the awk action inside a file to avoid problems with the quotes. awk.progfile:
{ if ($1 == "<testcase" && match($0, "notrun")) print substr($0,0,length($0)-2) "><skipped/></testcase>"; else print $0;}
And create add in your bat file:
awk -f awk.progfile gtestresults.xml > gtestresults-skipped.xml
Lastly you point the JTest processor as a Post-Build step to read the converted XML:
# Publish JUnit Test Result Report
Test Report XMLs: gtestresults-skipped.xml
Are you running your test executable with the correct flags (i.e. --gtest_output=xml[:DIRECTORY_PATH\|:FILE_PATH])?
From the --help output:
--gtest_output=xml[:DIRECTORY_PATH\|:FILE_PATH]
Generate an XML report in the given directory or with the given file
name. FILE_PATH defaults to test_details.xml.
The error on the Jenkins configuration page is a bit of a red herring.
Essentially, what's happening is that the test report xml file hasn't been generated by the build job. So, you then get this error:
Recording test results
No test report files were found. Configuration error?
Of course, the location must be configured correctly. For that, see this post:
How to configure test-reports on Jenkins CI working with grails?
So, how to fix the error? The key is to study the console output to check whether the tests did successfully run. Chances are they didn't, and that's why the error has happened.
Once you get the tests running successfully, assuming that you correctly configured the location, you should be ok.
You're using JUnit so it'll be a Java project. I'll note here in case it may help others, that we were running Xcode. The tests weren't being run.
Buried in Jenkins console output just above the error was this note:
note: RunUnitTests exited without running tests because TEST_AFTER_BUILD was set to NO.
Popping back into Xcode, and setting the UnitTests target's Test After Build flag to YES did the trick. That's under the Unit Testing section. You can also of course set the flag at the Project level, and change the target's to 'Other', setting a value of $(inherited).
Your results file is not stored at correct location and Jenkins plugin cannot find it. After your tests are executed and XML file is generated do you store it anywhere?
I suggest try make it working by replacing result.xml with '*' (assuming this is the only XML file that is supposed to be stored there) and if this is going to work then start working on correct file name.
We had the same issue in our configuration. Making sure that generated result XML is stored where the plugin expect it was the key. You can determine workspace root from your project config.
Jenkins has xunit plugin that converts googletest xml to junit format: https://plugins.jenkins.io/xunit/.
Example of pipeline
pipeline {
agent any
stages {
stage('Test'){
steps {
sh "run_tests.bash"
}
}
}
post {
always{
xunit (
thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ],
tools: [ GoogleTest(pattern: 'reports/*.xml') ]
)
}
}
}
Other useful links:
https://jenkins.io/doc/pipeline/steps/xunit/
https://jenkins.io/blog/2016/10/31/xunit-reporting/
Here is a windows batch version for converting the google-test "notRun" to junit "skipped" via windows batch. I know that there are more elegant ways, but this one only requires windows batch and does the job
rem convert gtest xml to junit compatible format (replace notRun by skipped)
IF EXIST %INTEXTFILE% (
IF EXIST %OUTTEXTFILE% (
del %OUTTEXTFILE%
waitfor fileSystemToDoItsStuff /t 1
)
FOR /f "tokens=1,* delims=¶" %%A IN ( '"type %INTEXTFILE%"') DO (
ECHO."%%A" | findstr /C:"DISABLED_">nul & IF ERRORLEVEL 1 (
SET modified=%%A
) ELSE (
SET string=%%A
SET modified=!string:/^>=^>^<skipped /^>^</testcase^>!
)
ECHO !modified!>> %OUTTEXTFILE%
)
del %INTEXTFILE%
waitfor fileSystemToDoItsStuff /t 1
move %OUTTEXTFILE% %INTEXTFILE%
)

Resources