Run a single Runner class through gradle command line - karate - gradle

I have more than one runner class created in my src/test/java folder. When i run the gradle command by
gradle test -DcatsRunner
it runs all the Runner files inside the folder and not just one. How to run only one Runner file using gradle command line
gradle test -DcatsRunner

You want to run a single test case with gradle.
Running gradle help --task test will give you the following help message:
$ gradle help --task test
Configuration on demand is an incubating feature.
> Task :help
Detailed task information for test
Path
:test
Type
Test (org.gradle.api.tasks.testing.Test)
Options
--debug-jvm Enable debugging for the test process. The process is started suspended and listening on port 5005.
--fail-fast Stops test execution after the first failed test.
--tests Sets test class or method name to be included, '*' is supported.
Description
Runs the unit tests.
Group
verification
The --test parameter is what you are looking for.
In you case:
gradle test --tests catsRunner
If you want to setup a more comprehensive test filtering, please read the test filtering gradle documentation.

Related

How pass Gradle command parameters to execute a task through Buildship

I know that if in Gradle I use: build -x test it builds and the test are not executed.
In STS with Buildship for support with Gradle, for example for Spring Integration
It has the following two tasks of my interest (build and test):
I can build with the following:
Because some test fails (randomly) I want skip the tests, so I tried
it fails with:
So I tried with:
And fails with
And with:
Nothing happens, only shows the following and stopping:
So how represent build -x test correctly with Buildship?
You must supply -x test as Program Arguments like this:
Or you just run assemble instead of build. assemble is a lifecycle task that aggregates all archive tasks in the project and, besides other tasks, does not execute check tasks, such as test.

Gradle - Corda flow tests fail when run from the command line

In my project I have a module that contains Corda flow tests written in Kotlin, and using JUnit. Most of the tests pass, except for the flow tests
My assumption is that this is because Corda flow tests require -ea -javaagent:lib/quasar.jar in the command line...
In my gradle.build file I've added
test {
jvmArgs "-ea -javaagent:lib/quasar.jar"
}
And then from the command line I'm running ./gradlew test but I get these errors from the flow tests:
java.lang.IllegalStateException
kotlin.UninitializedPropertyAccessException
Further Investigations
Running ./gradlew test --info suggests that the jvm arguments are being ignored altogether:
com.acme.FlowTests > Issuance flow should be signed by the initiator FAILED
java.lang.IllegalStateException: Missing the '-javaagent' JVM argument. Make sure you run the tests with the Quasar java agent attached to your JVM. See https://docs.corda.net/troubleshooting.html - 'Fiber classes not instrumented' for more details.
kotlin.UninitializedPropertyAccessException: lateinit property network has not been initialized
The problem was that I was specifying jvmArgs in the wrong module. Adding the following line to gradle.build of the module that contains the tests fixed the issue:
test.jvmArgs = ["-ea", "-javaagent:../lib/quasar.jar"]

Maven cucumber.options argument usage in Teamcity

I have a test automation framework and I am able to run my tests from maven command line with the following without any error:
mvn clean test -Pdev -Dserver="remote" -Dbrowser="ie" -Dcucumber.options="--tags #test"
I try to integrate it to teamcity but there are some problem with the arguments.
My config in Build Step:Maven:
Goals: clean test
path to pom file: is correct
Additional maven Command Line Parameters:
-Pdev
-Dserver=remote
-Dbrowser=ie
"-Dcucumber.options=--tags #test"
When I start the job, the test has been started but never ends, just it runs continuously and the job is stucked.
Any idea why? I'm pretty sure, cucumber.options arguments syntax is wrong, but without quotes it doesn't work at all. Please note, locally everything is working fine, there is no any error in arguments/maven profile etc.
Thanks!
If your TeamCity instance is running on Windows, the below syntax for defining Cucumber Options in the Additional Maven Command Line Parameters should work:
"-Dcucumber.options= --tags #test"
Not sure if it matters, but notice I have a space in between the = character and --tags

Android gradle skip build before running test?

I would like to skip the build process and directly run tests when I do
./gradlew connectedDevDebug
I could also use adb command but it will run test on only one deivce at a time.
There is currently no gradle tasks that just runs the tests.
But once you have installed (and run) the tests, you can (re-)run them directly with the am instrument command. To start them from your development machine's command line just run:
adb shell am instrument -w <test_package_name>/<runner_class>
You can copy the actual command from AndroidStudio's output. Just run the tests from AndroidStudio, and then scroll to the top of the test log view.
There is one caveat, am instrument does not create any test-reports. All test results are written to stdout. However you could pipe stdout into a file and create a report yourself. I.e. this tool can create an xml JUnit test report from the output of am instrument.
If you have made changes to the tests you can rebuild and install them with:
./gradlew installDebugAndroidTest
For detailed information and instructions about starting tests from the command line you can refer to the official article Test from the Command Line

Determining the Gradle test execution order

I was wondering whether it's possible to obtain information about test execution order somehow.
I have a project in Maven and all the tests are passing. After I migrated the project to Gradle, one of the tests started failing. The test itself is working: when I execute gradle test -Dtest.single=..., it passes. However, when I run the tests for the whole project, the test fails.
It's possible that some tests that run before the failing test do not release resources correctly and therefore the test fails. But I need to somehow find out which tests are causing this problem.
Tell Gradle to log more events about test processing. There is a documentation how to do that http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.testing.logging.TestLoggingContainer.html
The beforeTest method can be used to output details about each test before it is run, based on a TestDescriptor for each test:
test {
beforeTest { testDescriptor ->
println "${testDescriptor.className} > ${testDescriptor.name} STARTED"
}
}

Resources