Issue
I'm trying to unit test in my android application, and this is the simple test tutorial what i'm doing.
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class ServerListManagerTest extends AndroidTestCase{
@Test
public void testTrueIsTrue() throws Exception {
assertEquals(true, true);
}
}
The directory is like this, src\main\androidTest\java\some packages\ServerListManagerTest.java
I tried changing directory of this, and also build configuration. but android studio still doesn't recognize my unit test though build was successful.
This is my build.gradle in app,
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.kaist.se.pmpapp"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { java.srcDirs = ['src/main/java', 'src/androidTest/java'] } } }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
androidTestCompile 'org.robolectric:robolectric:2.4'
androidTestCompile 'junit:junit:4.12'
androidTestCompile group: 'junit', name: 'junit', version: '4.12'
}
What's wrong in my code????
Solution
I assume you're using Android Studio version 1.2, the latest at this time.
I don't think anything is wrong with your code. According to Jason Atwood's post, the problem seems related to gradle caching the previous results and not running it again. If you look at the "Gradle console", you'll see everything say "UP-TO-DATE". However, his suggestion of adding the "--rerun-tasks" option to the script parameters was not sufficient for me.
In addition to "--rerun-tasks", I had to turn off the in-process build and force it to call the external gradlew
tool. To do this, go to...
File > Settings > Build, Execution, Deployment > Compiler
Then un-check the "Use in-process build" option. Hopefully a future release of Android Studio will fix this and we can re-enable that option.
Answered By - Brian White
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.