Android 테스트 실행기가 '빈 테스트 도구 모음'을보고하는 이유는 무엇입니까?
IntelliJ / Android가 "Empty test suite"를보고하는 이유를 알아 내려고 여기 벽에 머리를 부딪 히고 있습니다. 두 개의 IntelliJ 모듈 (Eclipse의 "Projects")이있는 작은 프로젝트가 있습니다. 단위 테스트 모듈에는 맨 아래에 붙여 넣은 자체 AndroidManifest.xml이 있습니다. ActivityUnitTestCase
테스트가 Context
-object에 의존하기 때문에을 실행하려고합니다 .
기본 모듈의 패키지 이름은입니다 nilzor.myapp
. 테스트 모듈의 pacakge 이름은 다음과 같습니다.nilzor.myapp.tests
테스트 실행기가 testBlah()
-method를 테스트로 감지하지 않는 이유는 무엇 입니까?
<?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nilzor.myapp.tests"
android:versionCode="1"
android:versionName="1.0">
<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
which is needed when building test cases. -->
<application>
<uses-library android:name="android.test.runner"/>
</application>
<!--
This declares that this application uses the instrumentation test runner targeting
the package of nilzor.myapp. To run the tests use the command:
"adb shell am instrument -w nilzor.myapp.tests/android.test.InstrumentationTestRunner"
-->
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="nilzor.myapp"
android:label="Tests for nilzor.myapp"/>
</manifest>
그리고 여기 내 테스트 수업이 있습니다 :;
package nilzor.myapp.tests;
public class NilzorSomeTest<T extends Activity> extends ActivityUnitTestCase<T>{
public NilzorSomeTest(Class<T> activityClass){
super(activityClass);
}
@SmallTest
public void testBlah(){
assertEquals(1,1);
}
}
이클립스 용 임에도 불구 하고 테스트 기본 사항 , 활동 테스트 문서를 읽고이 Hello world 테스트 블로그를 따라가 보았습니다 . 테스트 러너가 내 테스트를 찾아 실행할 수 없습니다. 내가 뭘 잘못하고 있죠?
여전히 확신 할 수없는 몇 가지 질문은 다음과 같습니다.
- 단위 테스트 방법 위에 주석이 필요합니까?
- 메소드 앞에 "test"를 붙여야합니까, 아니면 JUnit 테스트 전용입니까?
- 의 하위 패키지에서 테스트를 할 수 있습니까
nilzor.myapp.tests
?
그러나이 게시물의 주요 질문은 테스트 러너가 내 테스트를 감지하지 못하는 이유입니다 .
테스트 클래스에 대한 기본 생성자를 제공해야합니다. 예를 들면 다음과 같습니다.
package nilzor.myapp.tests;
public class NilzorSomeTest extends ActivityUnitTestCase<ActivityYouWantToTest>{
public NilzorSomeTest(){
super(ActivityYouWantToTest.class);
}
@SmallTest
public void testBlah(){
assertEquals(1,1);
}
}
다른 질문에 대해 :
아니요. 내 테스트는 여전히 주석없이 실행되지만이를 사용하는 것이 좋은 습관이라고 생각합니다. 실행할 테스트의 크기를 지정할 수 있습니다. Android에서 @SmallTest, @MediumTest 및 @LargeTest 주석의 목적은 무엇인가요?를 참조하세요 . 자세한 내용은.
예, "test"접두사가 필요합니다. InteliJ는 "test"접두사가 없을 때 "method never used"경고를 표시하고 테스트 실행 중에 해당 메서드를 건너 뜁니다.
예. 내 테스트를 하위 패키지로 구성했는데 잘 작동하는 것 같습니다.
이 문제가 "갑자기"또는 "5 분 전에 작동 했음"이 발생하는 경우 내 솔루션은 실행 / 디버그 구성으로 이동하여 "Android 테스트"에서 구성을 제거하는 것입니다. 테스트중인 클래스를 리팩터링하면 (예 : 새 패키지로 이동) 이러한 구성이 손상되는 경우가 있습니다.
위의 어느 것도 나를 위해 그것을 수정하지 않았습니다. 도움이 된 것은 지침 을 따르는 것이 었습니다 .
테스트 구성 만들기
Android Studio에서 :
- 실행 메뉴 열기 -> 구성 편집
- 새 Android 테스트 구성 추가
- 모듈 선택
- 특정 계측 실행기를 추가합니다.
android.support.test.runner.AndroidJUnitRunner
새로 생성 된 구성을 실행합니다.
비슷한 문제가있었습니다. 왜 이런 일이 발생하는지 확실하지 않지만 Android Studio에서 "File"> "Invalidate Caches / Restart"로 이동하여 문제를 해결할 수있었습니다.
Android Studio에 도움이되는지 모르겠지만 Intellij-Gradle 충돌이 발생했습니다. 테스트 파일을 "마우스 오른쪽 버튼으로 클릭"하고 "파일 컴파일 ... Test.java"를 눌러 문제를 해결했습니다. 그 후 단일 테스트를 다시 실행할 수 있습니다.
Android Studio 2.3.1에서 동일한 문제가 발생했는데 AS의 버그였습니다. 버전 2.2.1에서 동일한 테스트를 실행하면 정상적으로 수행됩니다.
Cannary 채널에서만 Android Studio를 실행하는 경우 안정적인 버전도 설치하는 것이 좋습니다. http://tools.android.com/tips/using-multiple-android-studio-versions
나는 gradle
안드로이드 스튜디오가 업그레이드 될 때까지 잘 실행되는 테스트를 받았습니다.
Apart from adding a default constructor to your tests, you might need to do some of these things to get your test suite to work
Under src/
create androidTest/java/<your-package-name>/test
. Note the androidTest
. Anything else including instrumentTest
will not work.
Add this to build.gradle
sourceSets {
testLocal {
java.srcDir file('src/androidTest/java')
resources.srcDir file('src/androidTest/resources')
}
}
android{
sourceSets {
instrumentTest.setRoot('src/androidTest/')
}
}
dependencies{
testLocalCompile 'junit:junit:4.11'
}
task localTest(type: Test, dependsOn: assemble) {
testClassesDir = sourceSets.testLocal.output.classesDir
android.sourceSets.main.java.srcDirs.each { dir ->
def buildDir = dir.getAbsolutePath().split('/')
buildDir = (buildDir[0..(buildDir.length - 4)] + ['build', 'classes', 'debug']).join('/')
sourceSets.testLocal.compileClasspath += files(buildDir)
sourceSets.testLocal.runtimeClasspath += files(buildDir)
}
classpath = sourceSets.testLocal.runtimeClasspath
}
check.dependsOn localTest
Add this to the AndroidManifest.xml
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for my packaged app"
android:targetPackage="<my-package-name>.test" />
For Intellij 15 I resolved this issue by:
- Opening the 'Project Structure' settings
- Clicking 'Modules' (on left)
- 'Sources' Tab
a. Right click on your source directory (usually src) click 'Source'.
b. Right click on your test directory click 'Test'
c. Right click on your out directory click 'Excluded' - Go to 'Paths' tab
a. Click 'Use module compile output path' radio button
b. Select your output path directory for 'Output Path'
c. Select your test path directory for 'Test output Path' - Click Ok
Obviously, you need a target device as to run your tests as they are instrumented tests. For some reasons, Android studio sometimes does not ask you to point to this target device and just prompt the "Empty Test Suite" message. There are different ways to fix this, here are a few :
run your main app and select a target device or
go to the Run (Run/Run.../Edit Configurations) configuration and modify the Deployement Target Options
In my case, none of the previous answers worked. The solution was to simply move the test class to another package.
This happened under androidTest/
In my case that problem was caused due to mistake in my code, actually that was in application class, so target activity wasn't opened and test output prints
Empty test suite error
I have tried run tests directly from terminal with adb shell am instrument -w -r -e package your.package -e debug false android.support.test.runner.AndroidJUnitRunner
. With this it prints for you much more about exception.
I had this problem because I had this in my build.gradle:
testOptions {
execution "ANDROID_TEST_ORCHESTRATOR"
}
Even though I wasn't using the Android Test Orchestrator (must have copyied from the tutorials by mistake).
Commenting that out solved it for me.
None of the other solutions worked for me, but I was able to get this working simply by uninstalling the existing app or test suite, then running the tests.
In my case, the project I was working on had a couple of modules. None of the solutions I found for this error helped me, and then somehow I realized that if I added the testing dependencies in BOTH of the build.gradle files, the tests magically started working. It doesn't matter if your tests live in only 1 of the modules, both gradle files must include the dependencies and the testInstrumentationRunner value.
So, if like me, none of the other answers have helped you, try adding these lines to the build.gradle file of each of your modules:
android {
....
defaultConfig {
...
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
and then also add:
dependencies {
...
// Test
androidTestCompile 'com.android.support:support-annotations:23.4.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
I just renamed the file and the problem fixed.
I had the same issue, and the reason was my test class did not have Test at the end of the class name!
My issue was caused by an exception being thrown in the @BeforeClass
method of my test case. It some how wasn't causing the test to fail - I only found it by inspecting the logcat output.
I fixed the exception and suddenly my tests were running!
After facing the problem today - not being able to run the instrumented android tests with Empty suite error - I found a git issue about this problem and thanks to Stephan Linzner, I could run the tests.
tl;dr You have to right click the test package and not the class in order to make the tests run.
Reference: https://github.com/googlecodelabs/android-testing/issues/27#issuecomment-219074863
This article helped me: Empty test suite
Basically I had to create a package - instrumentTest/java - under my src directory, and put all the tests there. Then I could execute these tests individually.
I had a raw Java project where this was occurring. Simply Java + JUnit4. It definitely resides with something in your .idea/ or .iml files. I scrapped mine, re-imported, and finally the tests ran again.
The test class may excluded from the compilation. Fix it in setting-compiler-exclude.
Here are my debugging steps I go through when Android Studio all of a sudden decides to stop running / debugging tests (And boy does this happen embarassingly often!!):
- Build: → Rebuild project
- Restart Device: Restart your device/emulator and try again
- Device switch: if you have both a regular phone and an emulator unplug one and try running it with just one of the devices
- Android Studio: File--> Invalidate caches and restart
- Activity Monitor / Task Manager: sort processes by name, see if there is a nameless processes that's using up a lot of ram, this is a "ghost" process from Android studio that must be killed
- git revert: try stashing /reverting your latest code. Sometimes there is a compile error that Android Studio / gradle misses and it will just try to run uncompilable code.
- Uninstall then reinstall Android Studio.
I will add more fixes as I run into them!
I did nothing and the problem went away after half a day of pain, I opened and closed the projects many times, ran each class tests manually, maybe that fixed my it.
In Android studio with spock framework I've changed my gradle's version from 2.2.2 to 3.2.1 and all goes well.
The accepted answer didn't solve my problem. So I decided to copy ExampleInstrumentedTest
which is created by default in Android Studio and runs without any problems, renamed it during the copy process (no Refactor->Rename after copying!) and pasted the contents of my unit test into it. After that the error disappeared.
I experienced the "Empty test suite" error when trying to run local unit tests in my Android Studio 3.0 project.
After reading the Android Developer documentation, I quickly realised that the issue was caused by my gradle config which included the following lines.
testImplementation 'com.android.support.test:runner:0.5'
testImplementation 'com.android.support.test:rules:0.5'
The AndroidJUnitRunner class is a JUnit test runner that lets you run JUnit 3- or JUnit 4-style test classes on Android devices.
Since my tests were local and therefore not required to run on any device, removing the above com.android.support.test... entries enabled me to execute the unit tests.
I was doing some insertions in a db in the @BeforeClass method. I realised I had an object/database mapping problem. This data mapping problem was the cause of this issue for me.
In my case, I had my instrumented tests in androidTest/java/<package.name>/MyTestingClass
, but I had set my current build variant to "preproduction". And there's the point! As specified in Android Studio documentation:
By default, all tests run against the debug build type.
The message Class not found. Empty test suite.
kept appearing until I did this:
Add this line to my build.gradle:
android{ [...] testBuildType "preproduction" }
- Synchronised gradle.
- Delete my previous test configurations since they don't take this Gradle synchronisation into account.
Then I executed the tests again and this time they run just perfect!!!
I had this happen to me when I mistakenly marked a non mock class variable with the annotation @Mock
Removed the annotation and the tests ran successfully. This happened with Junit 4.5 on Android Studio
Not a solution but a workaround that will get you back on track quickly:
Firstly, find a test that works. I was writing a new test where I got the 'empty test suite' error. I ran other tests and they were working as usual.
Copy the test file that does work. Run it to make sure this copy works like the original.
Remove the body and replace it with your new test code.
The test should now work.
원인을 찾으려고 약 2 시간을 보냈지 만 소용이 없었습니다.
'programing tip' 카테고리의 다른 글
InputStream에서 File 객체를 만들 수 있습니까? (0) | 2020.08.22 |
---|---|
Linux보다 Windows에서 새 프로세스를 만드는 데 더 많은 비용이 드는 이유는 무엇입니까? (0) | 2020.08.22 |
"스트림이 이미 작동되었거나 닫혔습니다"를 방지하기 위해 스트림을 복사합니다. (0) | 2020.08.22 |
Razor에서 Visual Studio 코드 서식 비활성화 (0) | 2020.08.22 |
Eclipse의 유효성 검사에서 특정 폴더 또는 파일을 제외하는 방법은 무엇입니까? (0) | 2020.08.22 |