Gradle Wrapper compile and build code and run a single unit test - bash

Hey guys I am having a little trouble with the gradle wrapper.
Is there any good way to compile all my code, compile all my tests, and run a single test.
This is for a scripting command in a Jenkins pipeline.
I have used
./gradlew build, which runs all the tests
./gradlew build -x test, which compiles all main code and not allow me to run any tests
Thanks for any help

see the gradle documentation https://docs.gradle.org/current/userguide/java_testing.html#test_filtering
# Executes all tests in SomeTestClass
gradle test --tests SomeTestClass
# Executes a single specified test in SomeTestClass
gradle test --tests SomeTestClass.someSpecificMethod
gradle test --tests SomeTestClass.*someMethod*
# specific class
gradle test --tests org.gradle.SomeTestClass
# specific class and method
gradle test --tests org.gradle.SomeTestClass.someSpecificMethod

Related

Build successful but not executing tagged junit test cases using gradle command

I'm using below gradle command to run test cases :-
./gradlew integrationTest -Ptag=regression

How to skip test task when running sonarqube task?

When I execute sonarqube task, by default test task runs. How can I configure Gradle to not run tests when I specifically run sonarqube.
I want to configure this build.gradle.kts.
When I run
./gradlew sonarqube -x test
then tests are not executed.
I want to achieve the same by configuring in the build.gradle.kts file.

How to run multiple cucumber runners from maven command line

I've 2 CI flows , which flow needs to run it's own cucumber runner
RunnerATest
RunnerBTest
I'm using maven command line to run the tests (mvn test)
Is there a way to select a specific Runner from command line ?
Thanks
Maven Surefire Plugin - Running a Single Test
During development, you may run a single test class repeatedly. To run this through Maven, set the test property to a specific test case.
mvn -Dtest=TestCircle test
So you'd do just that. mvn -Dtest=RunnerATest test.

How to run only specific tests with Gradle and JUnit 5?

Using Gradle and its JUnit 4 support, I can choose a specific test using the --tests option like this:
$ ./gradlew test --tests de.mp.BarMT
This option is ineffective when using the JUnit 5 Gradle task. It is ignored silently when using the test tasks from the command line. The true work is done by junitPlatformTest anyway, and it does not support the option:
$ ./gradlew clean junitPlatformTest --tests de.mp.BarMT
…
Problem configuring task :junitPlatformTest from command line.
> Unknown command-line option '--tests'.
Does the JUnit 5 plugin support choosing specific tests?
Answering myself… A lot of time has passed, new versions came, and I can confirm that with Gradle 5.4.1 and JUnit Jupiter Platform 1.4.2, the simple configuration:
test {
useJUnitPlatform()
}
will allow running single tests as seen in https://stackoverflow.com/a/31468902/2621917, even when using weird names (from Kotlin):
gradle test --tests 'HtmlForwardInterceptorTest.should forward requests'

Gradle and spock few needed tests to run

my question is can i run by gradle a few needed for me spock tests?
I mean not packages and classes, only tests. I know the way how i can run one test:
./gradlew testTask --tests "*TestName*"
TestTask contains only include package where tests was placed.
I tried code like this:
./gradlew testTask --tests "*TestName*","*TestName2*"
It Doesn't work.Maybe someone know how i can do this?
According to the docs --tests is an option that you can repeat. So, you should be able to specifically pick multiple tests to run with:
./gradlew testTask --tests "*TestName*" --tests "*TestName2*"
For Gradle 3.x you can apply only one filtering rule to a single --tests switch. In your case I see two possible solutions:
You can create a wildcard that will satisfy tests you expect to run (and only them), e.g.
./gradlew testTask --tests "*TestName*"
this rule will satisfy both, TestName.java and TestName2.java
You can create separate test tasks and apply different filtering rule to them, e.g.:
./gradlew firstTestTask --tests "*TestName*" secondTestTask --tests "*TestName2*"
It is verbose, but you have a control over all filtering rules.
Please take a look to Gradle's documentation for more information: https://docs.gradle.org/3.3/userguide/java_plugin.html#test_filtering

Resources