Android Studio 3 does not run tests in Spock - android-studio

I updated Android Studio to version 3 and since then all my spock tests, when in a java module, do not run when trying to run them from inside the application (right click on groovy folder -> Run 'Tests in groovy'). I get a:
Class not found: "package.name.classname"Empty test suite."
Same if I try to run a single test.
If I run the test task from the gradle panel I get this:
error. Cause: unknown.
On the other hand:
Any spock tests in android modules run fine.
All my java tests in all my modules run fine.
All my tests (spock and java) run fine when running them from outside AS using gradle (gradlew clean test).
My setup:
gradle v4.1
android gradle plugin v3.0.0
java version compatibility v1.8
in my java modules i use the gradle groovy plugin
in my android modules i use the groovy android gradle plugin
A few things I tried after searching in both google and here:
changing the android gradle plugin back to v2.3.3 and gradle to v3.3
trying to copy all groovy classes to build/classes/java/test

So this is more of a workaround than an actual solution but it should give you your debugger back which is probably 90% of the value anyway:
You can run your test suite like:
./gradlew <module>:test --debug-jvm
And the jvm running your tests will suspend until a debugger attaches.
From Android Studio bring up the action chooser by pressing ctrl + shift + a (on linux anyway, check the equivalent for your OS) and select:
Attach to local process...
Once Android Studio attaches the tests will begin running.
The --debug-jvm flag can be used together with --tests to debug an individual test:
./gradlew <module>:test --tests fully.qualified.test.Test --debug-jvm

Related

Run a shell script before a gradle build in Android Studio?

Is it possible to run a unix shell script in Android Studio before every (gradle) build?
I'm having some trouble with gradle builds taking forever and one (admittedly bad) solution that works is to kill all java processes if they hold more than say 6Mb memory.
What I would like to do is run a shell script that does that before every build in Android Studio.
I'm not looking to add a gradle task to run before my build. That won't work because if I kill all java processes, gradle will also be killed.
So again:
Can I set up Android Studio (or gradlew) to run a script before building?
Instruction for Intellij Idea, but I hope it works for Android Studio
Edit configirations...
Select\create run configuration for gradle build. Add "before launch" option
Select ptoper option. For example - "Run external tool"

How to generate jacoco reports for specific module in android studio?

I am very new to this environment. I came from a native iOS background.
By using this https://blog.gouline.net/code-coverage-on-android-with-jacoco-92ec90c9355e, I am successfully generating the JACOCO test reports for my unit test class in my android project (app module only).
What I am doing is:
I simply create jacoco.gradle file in the main project.
Apply from: '../jacoco.gradle' in app/build.gradle file
Added below code in the app/build.gradle file
android {
...
buildTypes {
debug {
testCoverageEnabled = true
}
...
}
...
}
Open a terminal inside the Android Studio and run the command
like
**gradlew tasks**
To generate a report, run the command
**gradlew testBlueDebugUnitTestCoverage**
Finally I found my reports at this path: \app\build\reports\tests\testTabletDebugUnitTest
By using this http://vgaidarji.me/blog/2017/12/20/how-to-configure-jacoco-for-kotlin-and-java-project/ I have successfully generated the jacoco report for the both Espresso and Coverage test classes (UI and Unit Testing), and also this project includes both java & kotlin classes.
Now my question is: I want to generate the jacoco test reports for specific module out of all other modules in my app.
System Info:
Windows 10,
Android Studio 3.3.1,
Kotlin: ext.kotlin_version = '1.3.21'
Gradle:gradle:3.4.0-alpha01.
You can run jacoco for specific module from command.
Check at Android Studio the gradle window where you can find all jacoco tasks.
Open Gradle Window
Go to tasks -> Reporting
Find the jacoco task for the module you want to run and double click the task to run
Gradle Window

Running unit tests doesn't catch changes

I'm going through the kotlin koans repo (https://github.com/kotlin/kotlin-koans). Whenever I make changes to my .kt files and run the unit tests, the changes in the .kt files aren't reflected in the test results. I've been getting around this by running ./gradlew build before running the unit tests.
I'm using Android Studio as my IDE. Any idea what's happening?
There is bug in Android studio.
https://github.com/Kotlin/kotlin-koans/issues/90
https://youtrack.jetbrains.com/issue/KT-18948
When you are running test, project doesn't recompile.
You should build project and then run tests again.

Android Studio aar module loads lint.jar only on IDE Start or Module import

When using Android SDK with the gradle build system, one can include an android.aar file as a sub-project.
Within the aar, one can supply a lint.jar that implements custom lint checks (Source).
When executing gradlew build within the project root on the command-line, my library.aar is exploded and the lint.jar within is used for the lint checks. Even when I update the lint.jar within the library.aar, it is updated in the lint cache and the new lint.jar is used for the checks when I call gradlew build again.
If I build the same project with the same gradle command from within Android Studio 1.5, the library.aar is only exploded once on Module Import or on the IDE Startup.
The lint.jar is never updated when I update the library.aar in my sub-project and the old lint.jar from the IDE startup is still in use.
Is this a bug or am I doing something wrong?
Currently I work around it by executing the gradle commands on the command-line, but it would be nice if Android Studio would work in these cases too.

Intellij 14 gradle fails to run bower command

I am just starting to play with the JHipster framework / code generator using intellij 14.1.5 on OSX Yosemite. I have a simple app with a couple of domain objects which I have imported into Intellij as a gradle project. When I attempt to run the app via the gradle build "run" task, the build fails on the bower command. I can successfully run this gradle task from the osx terminal app AND from withing Intellij's terminal window. It fails when I invoke the run task from the from the gradle tasks pane or if I run it from the "run configurations" drop down in the toolbar. It feels like it fails when Intellij invokes gradle, but succeeds when gradlew is invoked in a terminal. I'm not sure why there would be a difference in these environments / invocations.
I have installed npm/gulp/bower/yoeman via nvm/node and am up on current versions (installed today). Node is at 4.1.1.
Posting this answer because no one has posted one yet. I have followed the recommendation of this other post. It fixes the Intellij app launcher on the mac to recognize the path for node commands. The original technique is described in apple.stackexchange.com. I am using this technique with the latest Intellij Idea 2016.1.3 and Intellij invoked gradle runs bower / npm just fine.
Just update gradle version.
Open gradle/wrapper/gradle-wrapper.properties
and change version like
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip

Resources