來源:http://jadewoo.iteye.com/blog/613915java
代碼以下:
import java.util.List;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Test extends TestCase {
private ApplicationContext context = null;
@Override
protected void setUp() throws Exception {
context = new FileSystemXmlApplicationContext(
"/WebRoot/WEB-INF/classes/applicationContext.xml");
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
public void getALl(){
// ComicCmsdataService sds = (ComicCmsdataService)context.getBean("comicCmsdataService");
ComicCmsdataDAO sds = (ComicCmsdataDAO)context.getBean("ComicCmsdataDAO");
List<ComicCmsdata> l = sds.findAll();
System.out.println("l.size():"+l.size());
for(ComicCmsdata c : l){
System.out.println(c.getId().getRetParm1()+" "+c.getId().getRetParm2());
}
}
}
用junit Test運行後,出現以下的錯誤:junit.framework.AssertionFailedError: No tests found in com.wichina.model.Test
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
解決辦法:在測試辦法前面加test,即把getAll()改成testGetALl()。這樣後就能夠運行了spring