I have let gradle generate a gradle app for me (gradle init --type=kotlin-application).
It users kotlin-test (org.jetbrains.kotlin:kotlin-test) as test framework.
However, when I invoke "./gradlew build" and a test fails, I get output where the actual failed test assertion is missing, for example
de.eekboom.eeksv.SimplestTest > testStreaming FAILED
java.lang.AssertionError at SimplestTest.kt:48
5 tests completed, 1 failed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///D:/dev/eeksv/build> /reports/tests/test/index.html
I can of course, open the linked index.html for test results, but that is a bit annoying.
Only when I run that specific test (from within IDEA) I get more helpful output like
expected:<3> but was:<2>
java.lang.AssertionError: expected:<3> but was:<2>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
...
at de.eekboom.eeksv.SimplestTest.testStreaming(SimplestTest.kt:48)
When I use Java and the gradle groovy DSL, I can fix this by configuring the test task:
testLogging {
events TestLogEvent.FAILED // Show specific test failures in output
exceptionFormat = TestExceptionFormat.FULL // Output full failure details
}
How can I do the same for kotlin?
Related
While publishing NUnit report in Jenkin getting an exception "ERROR: Step ‘Publish NUnit test result report’ failed: Could not read the XSL XML file. Please report this issue to the plugin author". I am using
.Net Core MVC App in C#
NUnit project
Jenkin
Using command "dotnet test ".\WebApp2nUnit\WebApp2nUnit.csproj" --logger:"trx;logFileName=Report.xml""
in freestyle jenkin project.
Although build success along with I could see test result report is forming but at the time of publishing this report getting below exception. I am using the NUnit plugin to publish this. Provided is the compete error message:
Test Run Successful.
Total tests: 3
Passed: 3
Total time: 5.3879 Seconds
C:\Program Files (x86)\Jenkins\workspace\WebApp2>exit 0
Recording NUnit tests results
Error in NUnit processing: Could not transform the NUnit report. Please report this issue to the plugin author
ERROR: Step ‘Publish NUnit test result report’ failed: Could not read the XSL XML file. Please report this issue to the plugin author
Finished: FAILURE
Please suggest.
Nishant
I added this package to my solution: https://www.nuget.org/packages/NunitXml.TestLogger/
Then the command used is:
dotnet test folder/project.csproj --filter "TestCategory=category" --results-directory ./folder/ --test-adapter-path:. --logger:"nunit;LogFilePath=TestResult.xml"
and to publish:
nunit testResultsPattern: 'folder/TestResult.xml'
apply plugin: 'base'
gradle tasks
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Configure test task
test {
dependsOn bar
}
Error
Could not find method test() for arguments
[build_740ewxgjzod99mmq37aj1jekp$_run_closure17#3e64d862]
on root project 'foo' of type org.gradle.api.Project.
In Gradle doc, it said:
Adds the standard lifecycle tasks and configures reasonable defaults
for the archive tasks:
adds build ConfigurationName tasks. Those tasks assemble the artifacts belonging to the specified configuration.
adds upload ConfigurationName tasks. Those tasks assemble and upload the artifacts belonging to the specified configuration.
configures reasonable default values for all archive tasks (e.g. tasks that inherit from AbstractArchiveTask).
As you can see, there is no test task, you can also verify in the source code:
public void apply(Project project) {
project.getPluginManager().apply(LifecycleBasePlugin.class);
BasePluginConvention convention = new BasePluginConvention(project);
project.getConvention().getPlugins().put("base", convention);
configureBuildConfigurationRule(project);
configureUploadRules(project);
configureUploadArchivesTask();
configureArchiveDefaults(project, convention);
configureConfigurations(project);
configureAssemble((ProjectInternal) project);
}
So, the test task you are looking for is in either 'groovy' (groovy plugin includes java plugin) or 'java' plugin Gradle doc:
> gradle build
:compileJava
:processResources
:classes
:jar
:assemble
:compileTestJava
:processTestResources
:testClasses
:test
:check
:build
BUILD SUCCESSFUL
Total time: 1 secs
Let me know if this makes sense.
I have simple build.gradle (or any build.gradle with task that has println)
println GradleVersion.current().prettyPrint()
task task1{
println 'task1 starting'
}
Now when I run $ gradle build I always see tasks executing or print output
task1 starting
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 1.291 secs
Why there is always output from println inside tasks?
If You have the following piece of code:
task task1 {
println 'task1 starting'
}
You're in configuration phase of a task. This phase is run during script evaluation. If You'd like to print something while task is executed You need to add an action for task.
It looks like:
task task1 << {
println 'task1 action'
}
This piece of code will be evaluated while the task is being run. << is exactly the same as invoking doLast method on Task's object. You can add many actions.
EDIT
I also highly encourage you to read this blog post.
from Chapter 55. The Build Lifecycle http://www.gradle.org/docs/current/userguide/build_lifecycle.html
// in `settings.gradle`
// println 'This is executed during the initialization phase.'
println 'This is executed during the configuration phase.'
task configure {
println 'This is also executed during the configuration phase.'
}
task execute << {
println 'This is executed during the execution phase.'
}
run with gradle help
output:
This is executed during the initialization phase.
This is executed during the configuration phase.
This is also executed during the configuration phase.
:help
Welcome to Gradle 1.10.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL
Total time: 1.882 secs
I have a Jenkins that run several task, included my tests with phpunit. Everything is working, the test are running but when a test fail the build is set like Succesfull and I don't get my notifications. I wanna that when a test fail, the build fail to notificate github and the developer too.
The notification system works OK when a build fail because I have migrations too that are working ok.
My phpunit.xml file look like this:
<phpunit
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
processIsolation="false"
stopOnError="true"
stopOnFailure="true"
stopOnIncomplete="true"
stopOnSkipped="true"
stopOnRisky="true"
strict="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="true"
And this is one of the outputs of Jenkins.
There was 1 error:
Undefined index: payroll
/tmp/app/test/unit/payroll/PayrollTest.php:24
FAILURES!
Tests: 311, Assertions: 392, Errors: 1.
BUILD FINISHED
Total time: 2 minutes 17.89 seconds
[INFO] HipChat notification sent to the following rooms: app
Finished: SUCCESS
Hints ? Best regards.
I launched the tests IDE (selenium) from jenkins and I uploaded the XUNIT plugin for having a nice report of test but at the end I obtained this message of ERROR :
Tests failed, see result file for details:
D:\FTP\stm_atos_automatisation\rapports\ff39\rapport_ff39.html ERROR: Build step failed with exception java.lang.NullPointerException: The types section is required.
at org.jenkinsci.plugins.xunit.XUnitProcessor.<init>(XUnitProcessor.java:65)
at org.jenkinsci.plugins.xunit.XUnitPublisher.perform(XUnitPublisher.java:111)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:726)
at hudson.model.Build$BuildExecution.post2(Build.java:185)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:671)
at hudson.model.Run.execute(Run.java:1766)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:381) Build step 'Publish xUnit test result report' marked build as failure Finished: FAILURE
Is there any way to solve this problem?
I was getting this error too when I first enabled the XUnit plugin.
I hadn't realized (or had forgotten) that I needed to add a report type to the XUnit build step configuration. To do so, click Add and then select the type of report you want parsed (for me it was PHPUnit-3.x). See this screenshot. You'll also have to specify the path to the XML report files that you want parsed. (I'm using Codeception, so it was tests/_log/*.xml.)