2

I'm trying to run a test on built dotnet core web app but I'm unable to perform it, as the method which I tried gives error as shown below

Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] git
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/myrepository/mywebapp # timeout=10
Fetching upstream changes from https://github.com/myrepository/mywebapp
 > git.exe --version # timeout=10
 > git.exe fetch --tags --progress https://github.com/myrepository/mywebapp+refs/heads/*:refs/remotes/origin/*
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision ae1432d0000a0ebsdse63sdd2dc20850dedd2a76c0643e (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f ae1432d0000a0ebsdse63sdd2dc20850dedd2a76c0643e 
 > git.exe branch -a -v --no-abbrev # timeout=10
 > git.exe branch -D master # timeout=10
 > git.exe checkout -b master ae1432d0000a0ebsdse63sdd2dc20850dedd2a76c0643e 
Commit message: "first commit"
 > git.exe rev-list --no-walk ae1432d0000a0ebsdse63sdd2dc20850dedd2a76c0643e  # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Restore PACKAGES)
[Pipeline] bat
[jenkins Pipeline] Running batch script

C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline>dotnet restore  
  Restoring packages for C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\dotnetapp.csproj...
  Generating MSBuild file C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\obj\dotnetapp.csproj.nuget.g.props.
  Restore completed in 1.18 sec for C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\dotnetapp.csproj.
[Pipeline] echo
packages are restored
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Clean)
[Pipeline] bat
[jenkins Pipeline] Running batch script

C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline>dotnet clean 
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10/18/2018 10:07:12 AM.
     1>Project "C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp.sln" on node 1 (Clean target(s)).
     1>ValidateSolutionConfiguration:
         Building solution configuration "Debug|Any CPU".
     1>Done Building Project "C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp.sln" (Clean target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.03
[Pipeline] echo
clean is done
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] bat
[jenkins Pipeline] Running batch script

C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline>dotnet build --configuration Release 
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 75.52 ms for C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\dotnetapp.csproj.
  dotnetapp -> C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\bin\Release\netcoreapp2.1\dotnetapp.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.36
[Pipeline] echo
build is done
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Pack)
[Pipeline] bat
[jenkins Pipeline] Running batch script

C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline>dotnet pack --no-build --output nupkgs 
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

[Pipeline] echo
nupkgs package is created
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (testing)
[Pipeline] bat
[jenkins Pipeline] Running batch script

C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline>"C:/Program Files/dotnet/dotnet.exe" test "C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline/dotnetapp.sln" --logger "trx;LogFileName=unit_tests.xml" --no-build 
Test run for C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\bin\Debug\netcoreapp2.1\dotnetapp.dll(.NETCoreApp,Version=v2.1)
Microsoft (R) Test Execution Command Line Tool Version 15.8.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
System.IO.FileNotFoundException: Unable to find tests for C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\bin\Debug\netcoreapp2.1\dotnetapp.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)

Test Run Aborted.
[Pipeline] step
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Publish)
Stage "Publish" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.UnsupportedOperationException: no known implementation of interface jenkins.tasks.SimpleBuildStep is named MSTestPublisher
    at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:478)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:402)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:341)
    at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:282)
    at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:201)....................
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:264)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
    at sun.reflect.GeneratedMethodAccessor414.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
    at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)

the script that I used is this

stage ('Restore PACKAGES') {
steps {
bat "dotnet restore "
echo 'packages are restored'
}
}
stage('Clean') {
steps {
bat 'dotnet clean'
echo 'clean is done'
}
}
stage('Build') {
steps {
bat 'dotnet build --configuration Release'
echo 'build is done'
}
}
stage('Pack') {
steps {
bat 'dotnet pack --no-build --output nupkgs'
echo 'nupkgs package is created'
}
}
stage('testing') {
steps {
  bat returnStatus: true, script: "\"C:/Program Files/dotnet/dotnet.exe\" test \"${workspace}/dotnetapp.sln\" --logger \"trx;LogFileName=unit_tests.xml\" --no-build"
    step([$class: 'MSTestPublisher', testResultsFile:"**/unit_tests.xml", failOnError: true, keepLongStdio: true])

}
  }

so how can I do testing for the build app ? are there any other way which I can try than this ? I refered this solution Jenkins integration for dotnet test any suggestion and articles will be very helpful thanks.

deepinside
  • 351
  • 1
  • 5
  • 15
  • Why are you not doing `script: "dotnet test"` or `script: "dotnet test dotnetapp.csproj"`? – omajid Oct 18 '18 at 05:16
  • @omajid I did try using script: "dotnet test dotnetapp.csproj" I get error as C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline>dotnet test dotnetapp.csproj MSBUILD : error MSB1009: Project file does not exist. – deepinside Oct 18 '18 at 05:30
  • That's very surprising. The restore line says it exists: `Restore completed in 75.52 ms for C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\dotnetapp.csproj.`. Is something deleting it? – omajid Oct 18 '18 at 05:37
  • no I did following stages after restore bat 'dotnet clean'bat 'dotnet build --configuration Release'bat 'dotnet pack --no-build --output nupkgs' then I tried using dotnet test dotnetapp.csproj – deepinside Oct 18 '18 at 05:50
  • This project is located in dotnetapp subdirectory. Try running `dotnet test ~/dotnetapp/dotnetapp.csproj` – Krzysztof Błażełek Oct 18 '18 at 06:33
  • @KrzysztofBłażełek ok I used dotnet test ./mathcalci/mathcalci.csproj and duild I got error as following C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline>dotnet test ./dotnetapp/dotnetapp.csproj Build started, please wait... Build completed. Test run for C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\bin\Debug\netcoreapp2.1\dotnetapp.dll(.NETCoreApp,Version=v2.1) Microsoft (R) Test Execution Command Line Tool Version 15.8.0 Copyright (c) Microsoft Corporation. All rights reserved. – deepinside Oct 18 '18 at 06:53
  • Starting test execution, please wait... System.IO.FileNotFoundException: Unable to find tests for C:\Program Files (x86)\Jenkins\workspace\jenkins Pipeline\dotnetapp\bin\Debug\netcoreapp2.1\dotnetapp.dll. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further. – deepinside Oct 18 '18 at 06:54
  • Try this: `dotnet test ./dotnetapp/dotnetapp.csproj --no-build --no-restore` – Krzysztof Błażełek Oct 18 '18 at 07:00
  • @KrzysztofBłażełek still I get the same error as above Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. – deepinside Oct 18 '18 at 07:07
  • Can you add content of your dotnetapp.csproj file? – Krzysztof Błażełek Oct 18 '18 at 07:26
  • @KrzysztofBłażełek netcoreapp2.1 3.0 – deepinside Oct 18 '18 at 07:42
  • It doesn't look like a test project to me. What is the project that contains your tests? – Krzysztof Błażełek Oct 18 '18 at 08:00
  • this is the content of dotnetapp.csproj file, do you mean dotnetapp.dll file? – deepinside Oct 18 '18 at 08:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182085/discussion-between-deepinside-and-krzysztof-blazelek). – deepinside Oct 18 '18 at 11:21

1 Answers1

1

The problem was caused by lack of test project in the solution.