我正在尝试在我的Android应用程序中进行单元测试,这是我正在做的简单测试教程。
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); } }目录是这样的, src\main\androidTest\java\some packages\ServerListManagerTest.java
我试着改变这个目录,并建立配置。 但android工作室仍然不承认我的单元测试,但建设成功。
这是我的应用程序build.gradle,
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' }我的代码有什么问题?
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????
最满意答案
我假设你使用的是目前最新的Android Studio 1.2版本。
我认为你的代码没有什么问题。 根据Jason Atwood的帖子 ,这个问题似乎与先前结果的gradle缓存有关,而不是再次运行。 如果您查看“Gradle控制台”,您会看到所有内容都显示为“UP-TO-DATE”。 然而,他建议在脚本参数中添加“--rerun-tasks”选项对我来说是不够的。
除了 “--Runun-tasks”之外,我不得不关闭进程内构建并强制它调用外部gradlew工具。 为此,请转到...
File > Settings > Build, Execution, Deployment > Compiler然后取消选中“使用进程内版本”选项。 希望未来的Android Studio版本能够解决这个问题,我们可以重新启用该选项。
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 > CompilerThen 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.
为什么Android Studio会说“未收到测试事件”?(Why does Android Studio say “Test events were not received”?)我正在尝试在我的Android应用程序中进行单元测试,这是我正在做的简单测试教程。
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); } }目录是这样的, src\main\androidTest\java\some packages\ServerListManagerTest.java
我试着改变这个目录,并建立配置。 但android工作室仍然不承认我的单元测试,但建设成功。
这是我的应用程序build.gradle,
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' }我的代码有什么问题?
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????
最满意答案
我假设你使用的是目前最新的Android Studio 1.2版本。
我认为你的代码没有什么问题。 根据Jason Atwood的帖子 ,这个问题似乎与先前结果的gradle缓存有关,而不是再次运行。 如果您查看“Gradle控制台”,您会看到所有内容都显示为“UP-TO-DATE”。 然而,他建议在脚本参数中添加“--rerun-tasks”选项对我来说是不够的。
除了 “--Runun-tasks”之外,我不得不关闭进程内构建并强制它调用外部gradlew工具。 为此,请转到...
File > Settings > Build, Execution, Deployment > Compiler然后取消选中“使用进程内版本”选项。 希望未来的Android Studio版本能够解决这个问题,我们可以重新启用该选项。
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 > CompilerThen 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.
发布评论