用JUnit做测试时出现的问题
测试类:
?
public class loginActionTest extends TestCase{ public void loginTest(){ LoginAction login=new LoginAction(); login.setUsername("admin"); login.setPassword("admin"); try {assertEquals("success", login.execute());assertEquals("admin123", login.getUsername());} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} }}
?
junit.framework.AssertionFailedError: No tests found in login.testcase.loginActionTest
??? at junit.framework.Assert.fail(Assert.java:47)
??? at junit.framework.TestSuite$1.runTest(TestSuite.java:90)
??? at junit.framework.TestCase.runBare(TestCase.java:130)
??? at junit.framework.TestResult$1.protect(TestResult.java:106)
??? at junit.framework.TestResult.runProtected(TestResult.java:124)
??? at junit.framework.TestResult.run(TestResult.java:109)
??? at junit.framework.TestCase.run(TestCase.java:120)
??? at junit.framework.TestSuite.runTest(TestSuite.java:230)
??? at junit.framework.TestSuite.run(TestSuite.java:225)
??? at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
??? 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)
出现错,然后仔细看看了JUnit资料,才知道自己所犯的错,在测试类中测试方法要以test开始.所有上面的代码中loginTest改为testLogin,只要以test开始就可以
?
1 楼 抛出异常的爱 2011-01-22 @Test