I wrote a build file to test if functional test failed then an exception will be thrown, and a HTML report is generated.
A small summery of the content of the build file:
1- It contains two tasks
2- First task is to generate from SoapUI projects functional tests in JUnit format
3- The failed test will be added to a list, declared in the task1.
4- Second Task uses the Ant component to generate the html reports
5- at the end of the second task, an exception is thrown if the List in not empty, and the content of the List will be displayed, using the throw new org.gradle.api.tasks.TaskExecutionException().
6- Of course there is a dependency: task2.dependsOn(task1)
However by adding the Task type, in my case are Test for task1 and TestReport for task2, then as result the Build is marked successful and the exception is not displayed at the end.
I need the exception to be thrown to use it further by Jenkins.
This is my first post in the forum If some one can help me that would be great.
From your summary of build script contents, it sounds like you are both trying to implement your own task (because you’ve mentioned some implementation details) and use the Test and TestReport tasks provided by Gradle.
You probably want to either let the tasks provided do all the work for you (if they do what you need) by just configuring them appropriately, or create your own Task implementation, where you wouldn’t be using Gradle’s Test and TestReport tasks at all.
If you are saying that everything worked as expected until you added the Test and TestReport task types to your task declaration, you already successfully completed the later. However, it’s difficult to pinpoint exactly what issues you might be having without seeing the relevant parts of the build script.
Thanks for your support.
from your reply I understand that the provided task types are used as prototype, to be implemented in a well defined way.
I though that each task has a type and it is better when we define it. (better design)
Without type declaration the results are successfully executed. However when I run > gradle test, the implemented tasks will not be executed or displayed.
I tried to make a dependency on test, it does not work too. Is there any proposal?
You are correct that each task has a type. If you don’t specify a task, you have a
DefaultTask rather than a task of type
TestReport. Both of these tasks inherit from
DefaultTask, either directly or from a subclass of it. If the implementation of the Task doesn’t do what you need it to, it is unnecessary and confusing to declare the type anyway (possible just because the name sounds relevant).
It is not enough to say you tried to make a dependency on test, but it did not work. You need to at least show how you tried to do this and what you mean by it didn’t work in order to get a useful suggestion.
I solved the problem of test task dependency as following: test.dependsOn(task2)
When I execute gradle test or gradle task2 it works successfully.
However when I execute gradle tasks the task2 will not be displayed on the task list. Actually all the tasks have to be displayed, isn´t it?
Gradle tasks --all will do the trick