Gradle build runss androidTest - android-gradle-plugin

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.

Related

How to skip tests in release part of build

We are currently using gradle-release-plugin.
Our release builds are twice as long due to unit and integration tests being run on both "SNAPSHOT" version and after the branch is "tagged".
here is the command line we execute in our release trigger:
./gradlew --info clean build release -Prelease.useAutomaticVersion=true
I read the plugin code and the doc and found "buildTasks" configuration but didn't find documentation or examples on them.
I'm sure we do something wrong but can't figure out what.
Thanks in advance

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.

Android, Gradle. How start specific instrumented test method?

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

Stop TeamCity Build when process exits with code 1

I am creating a TeamCity build configuration with a few steps. One of those steps is running tests using MSTest. Currently, my tests are failing (by design so I can test the build process), but the build steps after the step for running the tests happen, even though I can see the test process exits with code 1 (ie, something other than code 0) in the build log. It does mark the build as failed, but I'd prefer it if the steps in the build stopped once failing tests were detected. Is that possible and I'm just missing something in the configuration?
When you create build step there are select Execute step for execution policy. Where you should select Only if all previous steps were successful.
Here is it:
But in your case there are bug in the MsTest and NUnit build steps. Here is workaround. And here is related issue.

Maven reporting plugins do not execute if a unit test failure occurs

None of the plugins in the reporting section of Maven execute if there is a unit test failure.
I found that I can set maven.test.failure.ignore=true here - http://jira.codehaus.org/browse/SUREFIRE-247 The problem to this approach is now our hudson builds are successful even if there are unit test failures.
What I would really like to do is set the reporting plugin maven-surefire-report-plugin to run with the build plugins on a phase but I can't get this to work.
Any idea on how to get the Maven reporting plugins to execute if a unit test failure occurs?
Firstly run: mvn test OR mvn install. Then, if the tests fail, please run the following target to generate the reports for the test results executed above: mvn -Dmaven.test.skip=true surefire-report:report
In the link you posted:
With the latest version (2.1.2), I get
a message saying that "There are some
test failure," but I get no reports
anywhere whether or not I specify that
variable, or whether or not I specify
"testFailureIgnore" in the plugin
config. I got the reports fine with
2.0, but not with 2.1.2.
Do you need version 2,1 or can you work with a 2.0 version of Maven?
The error you see with 2.1.2 is because of forkmode settings which you need to perform in the plugin.
set forkmode=never and try it (I susppect there might problem in your useSystemclassloader property).
Otherwise make use of maven-surefire plugin version 2.5 which should definitel work and generate surefire rpeorts even though few test fails.
Please make use of surefire-report:report-only plugin if the reports are already generated after execution.
I had the same issue and it is due to a wrong call to the report plugin.
The correct execution of maven command is: mvn surefire-report:report
This will run the test phase by itself and if it fails it will generate the report anyway.
Check the documentation:
http://maven.apache.org/surefire/maven-surefire-report-plugin/report-mojo.html
Hope this helps!! :D