我的Java测试在Eclipse中运行良好.但现在,当我从运行菜单重新启动测试时,我收到以下消息:
No tests found with test runner 'JUnit 4'
Run Code Online (Sandbox Code Playgroud)
在.classpath文件中我有所有jar文件,最后有:
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Run Code Online (Sandbox Code Playgroud)
如何解决此错误并让测试再次运行?
我想运行以下测试:
package com.xxx.yyy;
import android.content.Context;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.xxx.yyy", appContext.getPackageName());
}
}
Run Code Online (Sandbox Code Playgroud)
但我在控制台中收到错误:
$ adb shell am instrument -w -r -e debug false -e class 'com.xxx.yyy.ExampleInstrumentedTest' com.xxx.yyy.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running …Run Code Online (Sandbox Code Playgroud) 尝试在Android Studio中执行测试时,我一直遇到以下错误:测试运行失败:无法找到以下内容的检测信息:ComponentInfo {.test/android.support.test.runner.AndroidJUnitRunner}
我的测试类在androidTest/java目录中并且有一个构造函数.我的build.gradle也是正确的.任何帮助表示赞赏.
测试类
@RunWith(AndroidJUnit4.class)
@LargeTest
public class AndroidUITests extends ActivityInstrumentationTestCase2<UserActivity>{
private UserActivity userActivity;
public AndroidUITests() {
super(UserActivity.class);
}
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
userActivity = getActivity();
}
@Test
public void testPhoneIconIsDisplayed() {
// When the phone_icon view is available,
// check that it is displayed.
onView(ViewMatchers.withId(R.id.groupCreate)).perform(click())
.check(matches(withText("Enter a name")));
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序/的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies { …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 Android 项目(使用 AndroidX)中运行标准的 ExampleInstrumentedTest,但得到“未找到测试”错误。我已经浏览了其他问题和文档,我很确定我已经做对了一切,但也许我忽略了什么?
这是我的应用程序的 build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.ext.junit.runners.AndroidJUnit4"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// Gradle automatically adds 'android.test.runner' as a dependency.
useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'
}
repositories {
mavenCentral()
maven {
url("https://oss.sonatype.org/content/repositories/snapshots")
}
maven { url 'https://jitpack.io' }
}
dependencies {
// Core library
androidTestImplementation 'androidx.test:core:1.0.0'
// …Run Code Online (Sandbox Code Playgroud) 我正在 Android Studio 中学习 Kotlin 初学者课程 - 在测试阶段,测试结果始终为0/0。我怎样才能完成这些测试?
代码由 Google Android 开发人员编写,应该可以完美运行。(我用的是同样的)。应用程序编译没有错误。代码在这里: https ://github.com/google-developer-training/android-basics-kotlin-words-app
我尝试了各种解决方案:
这可能与 Android Studio 版本 Bumblebee 或模拟器中阻止测试的某些设置有关。我怀疑这一点,因为在创建以前的应用程序时,在测试阶段发生了同样的事情(测试结果0/0)
测试结果说:
05/04 21:06:18:在 Pixel 3 API 29 上启动“navigate_to_words_...()”。应用程序重新启动成功,无需重新安装。运行测试
$ adb shell am Instrument -w -m -e debug false -e class 'com.example.wordsapp.NavigationTests#navigate_to_words_nav_component' com.example.wordsapp.test/android.support.test.runner.AndroidJUnitRunner 连接到设备上的进程 10870 'Pixel_3_API_29 [模拟器-5556]'。>
您对此有何看法?感谢您的时间!