2017-10-12 144 views
2

試圖遵循thisthis但沒有任何運氣。Android Studio 3.0「JUnit版本3.8或更高版本」

我正在使用Android studio 3.0和junit 4.12。 10.視窗

我曾嘗試:

  1. 移動JUnit的依賴了(試過測試編制和實施範圍) enter image description here
  2. 刪除運行測試 - 編輯配置... - 全部刪除在Android的JUnit和Android應用程序 enter image description here


我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); 
    } 
} 

UPDATE:

./gradlew測試

BUILD在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) 
+0

變化testCompileOnly到testImplementation – piotrek1543

+0

在我試圖說 - 沒有幫助 – pandemic

+0

嘗試從終端.... – tynn

回答

0

這是解決不了問題,只是一個混亂的解決方法(因爲太花時間來解決它):

卸載並再次安裝android studio 3.0。不要將 kotlin插件和android studio更新爲新版本。

相關問題