2017-06-05 38 views

回答

1

檢查gradle這個和你的等級:

搖籃:

testCompile 'org.robolectric:robolectric:3.3' 
testCompile 'junit:junit:4.12' 
testCompile 'org.assertj:assertj-core:1.7.1' 

在您的測試類:

@RunWith(RobolectricTestRunner.class) 
@Config(constants = BuildConfig.class, sdk = 25) 
public class YourTest { 

    @Test 
    public void shouldNotBeNull() throws Exception { 
     //put your test here for example 
    } 
) 

YourTest類應放在測試文件夾(不AndroidTest文件夾)

在Android Studio上:

  • 編輯配置
  • JUnit中,你必須改變工作目錄到$ MODULE_DIR $。 重要的是$ MODULE_DIR $。