【问题标题】:Android Studio 3.0 "JUnit version 3.8 or later expected"Android Studio 3.0“预计 JUnit 版本 3.8 或更高版本”
【发布时间】:2018-03-24 08:34:57
【问题描述】:

尝试关注thisthis,但没有任何运气。

我正在使用 Android Studio 3.0 和 junit 4.12。 Windows 10。

我尝试过的:

  1. 上移junit依赖(尝试测试编译和实现范围)
  2. 删除运行中的测试 - 编辑配置... - 删除所有在 Android JUnit 和 Android App 下


我的 graddle 看起来像这样:

apply plugin: 'kotlin'

dependencies {
    implementation project(':domain')
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompileOnly 'junit:junit:4.12'
    testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'io.reactivex.rxjava2:rxkotlin:2.1.0'
    testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    testImplementation 'com.nhaarman:mockito-kotlin:1.1.0'
    testImplementation 'org.amshove.kluent:kluent:1.14'
    implementation 'com.google.api.client:google-api-client-repackaged-com-google-common-base:1.2.3-alpha'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
}

我的测试如下所示:

package ***.roompanel.data;

import com.google.gson.FieldNamingStrategy;
import com.google.gson.Gson;
import com.google.gson.TypeAdapterFactory;
import ***.roompanel.data.RestApi.ApiFieldNamingStrategy;
import ***.roompanel.data.RestApi.ApiGsonBuilder;
import ***.roompanel.data.RestApi.ApiItemTypeAdapterFactory;
import ***.roompanel.data.RestApi.ApiService;
import ***.roompanel.data.RestApi.IApiService;
import ***.roompanel.data.repository.EventRepository;
import ***.roompanel.domain.model.event.Event;
import ***.roompanel.domain.repository.IEventRepository;

import org.junit.Before;
import org.junit.Test;

import java.util.Date;
import java.util.List;

import static org.junit.Assert.assertNotNull;


public class EventRepositoryTest {
    IEventRepository repo;

    @Before
    public void setUp() {
        TypeAdapterFactory typeAdatperFactory = new ApiItemTypeAdapterFactory(); // system to
        FieldNamingStrategy fieldNamingStrategy = new ApiFieldNamingStrategy();
        Gson gson = new ApiGsonBuilder(typeAdatperFactory, fieldNamingStrategy).build();

        IApiService service = new ApiService(gson);
        this.repo = new EventRepository(service);
    }

    @Test
    public void events_void_success() throws Exception {
        Date start = new Date(2017,10,01);
        Date end = new Date(2017,10,12);

        List<Event> events = (List<Event>) repo.load(start, end);

        assertNotNull(events);
    }
}

更新:

./gradlew test

在 25 秒内构建成功 53 个可操作的任务:30 个已执行,23 个是最新的

堆栈跟踪:

java.lang.RuntimeException: Stub!
    at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
    at junit.textui.TestRunner.<init>(TestRunner.java:54)
    at junit.textui.TestRunner.<init>(TestRunner.java:48)
    at junit.textui.TestRunner.<init>(TestRunner.java:41)
    at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:224)
    at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:207)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:61)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

【问题讨论】:

  • 将 testCompileOnly 更改为 testImplementation
  • 如我所尝试的 - 没有帮助中所述
  • 尝试从终端运行./gradlew test....
  • 用 gradlew @tynn 的输出编辑了我的问题
  • 可以尝试:“Go to Run -> Edit Configurations”并删除所有“Android Junit”配置吗?

标签: java android junit kotlin


【解决方案1】:

这不是解决方案,只是一个混乱的解决方法(因为解决它花费了太多时间):

卸载并重新安装android studio 3.0。不要更新 kotlin 插件和 android studio 到更新版本。

【讨论】:

    猜你喜欢
    • 2015-08-18
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 2011-01-26
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多