I have a problem when trying to run some Android JUnit tests inside IntelliJ Idea.
My project is an Android Library project using Gradle. When I run my tests, IntelliJ complains with the following error:
Class not found: "com.domain.app.ClassTest"
But ClassTest
is present inside the test package.
Here's my build.gradle:
apply plugin: 'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
dependencies {
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
compile 'com.android.support:support-v4:19.1.+'
compile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
}
android {
compileSdkVersion 18
buildToolsVersion "19.0.3"
defaultConfig {
versionName "1.0"
versionCode 1
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
res.srcDirs = ['res']
}
androidTest {
java.srcDirs = ['src/test/java']
}
}
lintOptions {
abortOnError false
}
}
My project structure:
src
|_ main
|_ java
|_ com.domain.app
|_ test
|_ java
|_ com.domain.app
I'm using IntelliJ IDEA 13.1.1.
Thanks.
Right-click the test root folder or package in the test root folder in which you want to create a new test and select New | Java Class. Name the new class and press Enter . Press Alt+Insert and select Test Method to generate a new test method for this class. Name the new method and press Enter .
Go to Project Structure -> Modules -> your_module -> Paths
.
The value for 'Output path
' should be filled in, but 'Test output path
' will not be. Copy the text that's in 'Output path
', paste into 'Test output path', but change the final 'build/intermediates/classes/debug
' to 'build/test-classes
'. This is because the gradle android test plugin currently dumps all compiled test output (for all variants) into the same directory. This means that currently variants are not fully supported.
Source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With