Android, Gradle. How start specific instrumented test method? - android-gradle-plugin

When I want to start specific local unit test (in folder "test") I start (Dev is buildType):
gradlew testDevUnitTest --tests com.example.StringUtilTest.testMethod
OK. It's work.
But also I want to start specific instrumented test method (in folder "androidTest").
gradlew connectedDevAndroidTest --tests com.example.StringUtilTest.testSelectLanguageFragment
But I get error:
> Unknown command-line option '--tests'.

You can run all tests in a specific test class like this
gradlew connectedDevAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.StringUtilTest
You can run a single test in a specific test class like this
gradlew connectedDevAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.StringUtilTest#testSelectLanguageFragment
More info at https://developer.android.com/studio/test/command-line.html

Related

How to pass data provider thread count parameter from build.gradle to testng.xml

I am looking to pass data provider thread count value from command line an then pick this parameter in build.gradle and use it inside useTestNg() inside the test task. Is this possible?
For example:
Command: gradle clean build test -Pdataproviderthreadcount=5
Can this be captured using systemPropeties and the value to be used in useTestNg()
Since dataproviderthreadcount is a VM option, I used this as below and it worked as expected. My project is a Cucumber, Gradle and testNG.
TEST_ENV=STG BROWSER=chrome ./gradlew clean build -Dorg.gradle.jvmargs=-Ddataproviderthreadcount=2
You can also refer How can I pass VM arguments to gradle from command line?

How to run CTest test in debugger

Suppose in CMakeLists.txt I have
add_executable(mytarget main.cpp)
enable_testing()
add_test(mytarget_test0 mytarget -option0)
Is there any easy way how can I run mytarget in GDB with all command line options from some particular CTest test? (Other than searching for test in CMakeLists and then copy-pasting add_test parameters to command line manually?)
Real life scenario: I run all tests using ctest, one fails, I want to open it in debugger quickly.
In other build systems there are command line parameters to use gdb, for example in Meson meson test --gdb testname , in bazel bazel --run_under=gdbserver. I did not found anything similar for CTest
It is possible to get test command with arguments:
ctest -R $regex_matching_test -V -N
As output you will get something like:
Test project ../cmake-build-debug-gcc7
Constructing a list of tests
Done constructing a list of tests
1: Test command: ../cmake-build-debug-gcc7/my_tool "-v" "test0"
Test #1: my_tool_test0
Total Tests: 1
Then using regexp it is possible to grab command line args for gdb
I use the following procedure:
make clean
make # Build target and all unit tests
make test # Run all unit tests: make test
You will get an result list and some output, depending of the unit test frame work. Fix the issue and re-run the failed test within gdb until it succeeds. Restart the whole procedure.
In case you are using an IDE (e.g. QtCreator) it is easy to debug through the failed test case.

Empty test suite error when running unit test case in intellij

I check out the source code of Cassandra, and I want to run a unit test case in debug mode to understand how it works
Below is my JUnit run configuration set up. The code can compile correctly using ant. And I tried both targets build and build-test.
IntelliJ can pick up the class in the run configuration, but when I run this profile, I got.
Process finished with exit code 1
Class not found: "org.apache.cassandra.tools.SSTableExportTest"
Empty test suite.
What part do I need to change the configuration so that IntelliJ can run this unit test cases?
Since you're trying to debug Cassandra. You can reference https://wiki.apache.org/cassandra/RunningCassandraInIDEA. They have already set up a ant target to generate required configurations.

Log which Test Executor is running particular test?

I configured my tests to run in parallel:
In my build.gradle:
test{
maxParallelForks 2
forkEvery 0
}
./gradlew build --max-workers=8 --parallel
But additionally I would like to know which executor is running particular test.
Is it possible to log such information?
I've tried to use --debug option but I doesn't appear there.
the worker id is stored as system property and you can access it via within your test named System.getProperty('org.gradle.test.worker') from within your test.

Gradle build runss androidTest

Using gradle 2.2.1 and com.android.tools.build:gradle:1.5.0
When I run ./gradle build in the console the build fails at step :testDebugUnitTest.
It fails because it tries to run a InstrumentationTestCase that should not happen.
What am I missing here?
This is normal. It's because build depends on other tasks. You can see these tasks by running gradle tasks --all.
For build it will show this: build - Assembles and tests this project. [assemble, check].
The check task is configured like this: check - Runs all checks. [assembleDebug, lint, test]
The test task like this: test - Run unit tests for all variants. [testDebugUnitTest, testReleaseUnitTest]
And that is why you see the testDebugUnitTest show up when you run the build task.
So if you just want to build without testing, you need to run gradle assemble. And if you want to save time and only build the variant you need, you can run gradle assembleDebug, for example.