[英]Android - Code coverage test errors
到目前為止,我一直在嘗試進行覆蓋代碼的測試,以便在IntelliJ中工作幾個小時,但沒有成功。
首先,項目中不包含junit的“ Run with coverage>”會產生以下錯誤(顯然)
線程“主”中的異常java.lang.NoClassDefFoundError:junit / textui / ResultPrinter
將junit 4.11和hamcrest-core 1.3添加到庫中,然后“覆蓋運行”:
! 預期的JUnit版本3.8或更高版本:
java.lang.RuntimeException:存根!
現在,我讀到更改模塊選項中的依賴順序可以解決此問題。 因此,更改順序后,我得到此錯誤:
junit.framework.AssertionFailedError: Exception in constructor: testMakeTextView (java.lang.NoClassDefFoundError: be/dave/DiversoScoreApp/MyActivity
at be.dave.DiversoScoreApp.MyActivityTest.<init>(MyActivityTest.java:20)
指向以下代碼:
public class MyActivityTest extends ActivityInstrumentationTestCase2<MyActivity> {
MyActivity myActivity;
public MyActivityTest() {
super("be.dave.DiversoScoreApp", MyActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
myActivity = getActivity();
}
public void testMakeTextView() throws Exception {
TextView textView = myActivity.makeTextView("Test-text", 50);
TextView textView1 = myActivity.makeTextView("Diverso", 75);
assertEquals("TextView Text should be correct", textView.getText(), "Test-text");
assertNotSame("TextView Text should fail", textView1.getText(), "Not Diverso");
}
}
我已經在谷歌上搜索了,但是到目前為止我還沒有找到解決方案。
如果嘗試測試testMakeTextView方法,則應使用@Test符號對其進行注釋。 所以
@Test
public void testMakeTextView()
同樣,setUp()方法具有@Before注釋,而不是我認為的@Override。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.