2016-01-06 21 views
2

我正在嘗試Intellij 16 EAP,我無法正確導入其中的一個Android項目。該robolectric測試不確認爲項目Intellij 16 - 單元測試未被識別爲Android模塊項目的一部分

enter image description here

我進口的項目是可以在github上找到一個樣本項目的一部分:

https://github.com/robolectric/deckard

這是構建。 gradle文件:

buildscript { 
    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:1.5.0' 
    } 
} 

repositories { 
    jcenter() 
} 

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion '23.0.2' 

    defaultConfig { 
     minSdkVersion 18 
     targetSdkVersion 23 
     versionCode 2 
     versionName "1.0.0-SNAPSHOT" 
     applicationId "com.example" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 

    packagingOptions { 
     exclude 'LICENSE.txt' 
    } 
} 

dependencies { 
    // Support v4 
    compile 'com.android.support:support-v4:23.1.1' 

    // Espresso 
    androidTestCompile 'com.android.support:support-annotations:23.1.1' 
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1' 

    // Robolectric 
    testCompile 'junit:junit:4.12' 
    testCompile 'org.hamcrest:hamcrest-library:1.3' 
    testCompile 'org.apache.maven:maven-ant-tasks:2.1.3' // fixes issue on linux/mac 
    testCompile 'org.robolectric:robolectric:3.0' 
} 

爲什麼會發生這種情況的任何線索? 1)如果我從gradle中刪除所有android插件,並且只添加java插件,則立即識別單元測試並將它們添加到項目中。然後,只要我切換回android插件,intellij再次刪除它。 2)我試過Intellij 15和Android Studio 2.0,我得到的結果相同

+1

你爲什麼不使用Android Studio?最新版本的AS完全支持單元測試。 – EJK

+1

這是一個具有其他要求的大型多模塊項目。比如java spring爲其他模塊。 Intellij ultimate只是android studio的大哥哥,但總是比android功能落後2個月。與android工作室相比,java工具在intellij後面延遲了兩個月。 –

回答

1

經過一番挖掘,我發現這似乎是預期的做事方式。您只能隨時在項目中輸入檢測測試或單元測試。您可以在「構建變體」窗口中切換2。

enter image description here

我還發現其中15:30這個怪異的行爲是這樣描述視頻https://www.youtube.com/watch?v=vdasFFfXKOY&index=3&list=LLM9iluZir-2dWQTQ-WfJdbw。他還表示,它將在Android Studio 2.0中修復,但通過測試顯示相反。

+0

我有同樣的經歷。我似乎無法打開兩種類型的測試。如果我將其標記爲構建變體中的測試源,並重新啓動,則工作正常。在同一時間同時工作將不起作用。將來能夠更好地整合它將會很高興。使用IntelliJ 2016.1 – ObjectiveTruth

+0

要添加,您必須選擇正確的構建變體,以某種方式將文件夾標記爲測試源(在項目結構中或右鍵單擊標記爲..),然後按重新啓動/無效緩存選項。但是每當你想要切換現在令人討厭但可行的測試類型時,就得這樣做 – ObjectiveTruth

0

可能你必須在模塊設置中將測試文件夾標記爲「測試文件夾」。 Ctrl + alt + shift + S enter image description here

還可以更好地使用來自金絲雀通道的Android Studio 2.0。它基於Intellij 15.

+0

a)我已經完成了這項工作,但只要gradle項目重新導入,模塊設置中的更改將被刪除。 b)我更喜歡使用intellij:> –

+0

test {classpath = project.sourceSets.test.runtimeClasspath + files(「$ {projectDir}/test」)}或sourceSets {test {resources {srcDir「test」}}} – Mistic92

+0

我不喜歡認爲問題在於gradle設置。如果我使用「gradlew test」從命令行運行測試,例如測試運行良好。這與intellij有關。附:我確實嘗試了你提到的但沒有任何事發生 –