[英]JUnit test methods are not executing
我有一個DateAdapter類,其中通過2種方法mrashall和unmarshall將日期類型編組為String類型並將字符串數據類型編組為Date類型。 所以我的測試方法沒有運行。
public class DateAdapter extends XmlAdapter<String, LocalDate> {
private static final String FORMAT = "yyyy-MM-dd";
/**
* Java Type => XML
*
* @param date unmappable Java object (date)
* @return desired XML representation
* @throws Exception
*/
public String marshal(LocalDate date) throws Exception {
if (date == null) {
return null;
}
return date.toString(FORMAT);
}
/**
* String Type => Java Type
*
* @param dateString String needs to parse into java type
* @return desired Java Type representation
* @throws Exception
*/
@Override
public LocalDate unmarshal(String dateString) throws Exception {
if (StringUtils.isNotBlank(dateString)) {
DateTimeFormatter formatter = DateTimeFormat.forPattern(FORMAT);
DateTime dateTime = formatter.parseDateTime(dateString);
return dateTime.toLocalDate();
}
return null;
}
}
我正在使用Junit,testNG,maven 2.2和Eclipse Juno。 右鍵單擊測試用例將不會執行測試方法。
public class DateAdapterTest {
/* Date adapter is a class to marshall date type into String and unmarshall
viseversa.
*/
DateAdapter dateAdapter;
private static final String DATE_FORMAT = "2014-01-01";
private static final LocalDate DATE = new LocalDate(2014, 01, 01);
@BeforeClass
public void setUp(){
dateAdapter = new DateAdapter();
}
/*
* @param Date Date type
* @return String String data type date
* @throw Exception
*/
@Test
public void testMarshal() throws Exception{
String dateString = dateAdapter.marshal(DATE) ;
assertEquals(DATE_FORMAT, dateString);
}
/*
* @param String String data type
* @return date LocalDate type date
* @throw Exception
*/
@Test
public void testUnmarshal() throws Exception{
LocalDate date = dateAdapter.unmarshal(DATE_FORMAT);
assertEquals(DATE , date);
}
}
java.lang.NoSuchMethodError: org.junit.runner.Request.classWithoutSuiteMethod(Ljava/lang/Class;)Lorg/junit/runner/Request;
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestMethodReference.createRequest(JUnit4TestMethodReference.java:31)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestMethodReference.<init>(JUnit4TestMethodReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:54)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
首先,您必須決定使用哪個框架:JUnit或TestNG。 一旦決定要檢查使用的@Test
批注。 我猜您是使用TestNG中的@Test
標記了測試,並嘗試使用JUnit運行測試。
升級到Junit 4.4,這是一個老問題,現在應該修復。 參見http://www.java-tutorial.ch/software-testing/junit-error-classwithoutsuite方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.