When you want to implement Java library testing in Spock with multi-module in Gradle in Android Studio 3

What you want to do

I'm using Gradle in Android Studio 3.x and it's multi-module and includes Java libraries.

I want to implement the test of the Java library in Spock.

Introduction

There are various ways to install Spock, but I will add it to the module build.gradle. However, the important point of this article is the destinationDir on the last line.

apply plugin: 'groovy'
dependencies {
    testCompileOnly 'org.codehaus.groovy:groovy:2.5.3'
    testCompileOnly('org.spockframework:spock-core:1.2-groovy-2.5') {
        exclude module: 'groovy-all'
    }
}
compileTestGroovy.destinationDir = compileTestJava.destinationDir

Commentary

When executed from the triangle that appears to the left of the test class in hoge.groovy, gradle's tax runs compile (compileTestGroovy) as groovy and .class is generated, but it is hoge / build / classes / groovy / test Generated in / . スクリーンショット 2018-11-17 21.37.41.png

But Test in Android Studio? Seems to be JUnit, so it seems that it refers to .class of hoge / build / classes / java / test /. As a result, the test cannot be executed with an error of Class not found:" hogehoge "Empty test suite..

Therefore, set compileTestGroovy.destinationDir to the same .class output destination as Java.

Recommended Posts

When you want to implement Java library testing in Spock with multi-module in Gradle in Android Studio 3
Code to use when you want to process Json with only standard library in Java
When you want to dynamically replace Annotation in Java8
You are currently using Java 6. Solution in Android Studio Gradle
Code used when you want to process Json with only the standard library in Java (improved version) gson unnecessary
Source to display character array with numberPicker in Android studio (Java)
Java to C and C to Java in Android Studio
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
3 ways to import the library in Android Studio
When you want to bind InputStream in JDBI3
A note when you want Tuple in Java
Android Studio memo that you want to display Toast characters in large size
[Android Studio] I want to use Maven library on Android
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
[Ruby + Rails] When you want to register in Mailchimp's mail list together with user registration
Refer to C ++ in the Android Studio module (Java / kotlin)
How to write in Model class when you want to save binary data in DB with PlayFramework
Use JLine when you want to handle keystrokes on the console character by character in Java
Streamline Java testing with Spock
When you want to explicitly write OR or AND with ransack
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
How to dynamically switch JDK when building Java in Gradle
I want to implement various functions with kotlin and java!
docker-compose.yml when you want to keep mysql running with docker
lombok.config when you want to pass @Qualifier to @RequiredArgsConstructor with lombok
In Java 10, when you do gradle eclipse and JavaSE-1.10 comes out, ...
ProxyFactory is convenient when you want to test AOP in Spring!
[Java] I want to perform distinct with the key in the object
Try to implement Yubaba in Java
[Words spelled to me when I was in the first grade ⑦] What I want you to include at least with the Visual Studio Code extension
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
[Android Studio] What to try when you get into error spitting hell
(Limited to Java 7 or later) I want you to compare objects in Objects.equals
I want to ForEach an array with a Lambda expression in Java
[For beginners] When you want to say that the JVM (-D) option does not work with the java -jar command, or that the library is buggy.
How to implement date calculation in Java
How to implement Kalman filter in Java
Try to implement n-ary addition in Java
How to implement coding conventions in Java
If you get angry with java.lang.UnsupportedClassVersionError: com / android / build / gradle / AppPlugin: Unsupported major.minor version 52.0 in built gradle after Android Studio 2.3
How to use ExpandableListView in Android Studio
When I try to build a Google Map template in Android Studio, I get angry with Files \ Java \ jdkXXX \ bin \ java.exe'' finished with non-zero exit value 2.
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
When you want to notify an error somewhere when using graphql-spring-boot in Spring Boot
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
I want to send an email in Java.
Static code analysis with Checkstyle in Java + Gradle
I tried to implement deep learning in Java
I want to use java8 forEach with index
I want to pass APP_HOME to logback in Gradle
When you want to use the method outside
rsync4j --I want to touch rsync in Java.
[Swift] Use nonzeroBitCount when you want popcnt in Swift
Try to implement TCP / IP + NIO with JAVA
[Java] 4 steps to implement splash screen on Android
Difficulties when implementing Alarm Manager in Android Studio
[Ruby] When you want to replace multiple characters
You don't have to write for twice when you make a right triangle in Java
When executing in parallel with Java, I'm addicted to not paying attention to thread safety
You also need to specify the host when debugging remotely with Java 9 or later