package test;
import static org.junit.Assert.*;
public class Test {
@Test
public static void main(String[] args) {
// TODO Auto-generated method stub
assertEquals(0, voidMethod(), 0);
}
static int voidMethod()
{
return 0;
}
}
感謝您需要導入JUnit測試類。使用這個:
import org.junit.Test;
爲了不與此導入衝突,最好還是將名稱命名爲Test
以外的方法。
此外,您不能使用靜態方法作爲Junit測試方法,並且您的Junit測試不應該有參數。你會得到一個異常,說明測試方法不應該是靜態的,並且測試方法不應該帶參數。
Junit測試的重點在於您有許多可以獨立運行的獨立測試。您沒有任何參數傳入測試。您需要的一切應該在測試中或在使用@Before
註釋之一進行測試之前進行設置。
嘗試是這樣的:
package test;
import static org.junit.Assert.*;
import org.junit.Test;
public class TestClass {
@Test
public void myTestMethod() {
// TODO Auto-generated method stub
assertEquals(0, voidMethod(), 0);
}
static int voidMethod()
{
return 0;
}
}
製作當然你也有Java Build Path中的junit.jar - > Order and exports – AlexWien
ok我已經在它裏面選擇了這個文件並且說OK。仍然錯誤不走。 – user1079065