我在使用 junit 运行它时遇到以下问题:除了testValidatePanelistIDHwid
. 这是我在此类中添加的新方法,所有其他方法都可以正常工作。
junit.framework.AssertionFailedError: Method "testValidatePanelistIDHwid" not found
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestCase.runTest(TestCase.java:147)
at junit.framework.TestCase.runBare(TestCase.java:127)
import junit.framework.TestCase;
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import xys.model.common.BusinessObjectException;
import xys.class.model.common.util.ValidationUtility;
public class ValidationUtilityTest extends ServletTestCase
{
ValidationUtility validationUtil = new ValidationUtility();
public void begin(WebRequest request){}
public void setUp() throws Exception
{
super.setUp();
}//end of SetUp
protected void tearDown() throws Exception
{
super.tearDown();
}
public void testIsMessageOfCorrectLength()
{
boolean isCorrectLen = ValidationUtility.isMessageOfCorrectLength("Test",4);
assertTrue("Message is not correct.",isCorrectLen == true);
isCorrectLen = ValidationUtility.isMessageOfCorrectLength("Test",3);
assertFalse("Message is longer than the limit.",isCorrectLen == true);
isCorrectLen = ValidationUtility.isMessageOfCorrectLength("Test",8);
assertTrue("Message is not longer.",isCorrectLen == true);
try
{
isCorrectLen = ValidationUtility.isMessageOfCorrectLength(null,8);
// fail("InputString is null.");
}
catch(Exception e)
{
System.out.println("ValidationUtilityTest:testIsMessageOfCorrectLength");
}
}
public void testValidateCommandInstanceId()throws BusinessObjectException
{
boolean isValidCmdInstID = false;
isValidCmdInstID = ValidationUtility.validateCommandInstanceId(341);
assertTrue("Command Instance ID 341 is not valid.", isValidCmdInstID == true);
isValidCmdInstID = ValidationUtility.validateCommandInstanceId(400);
assertTrue("Command Instance ID 400 is not valid.", isValidCmdInstID == true);
isValidCmdInstID = ValidationUtility.validateCommandInstanceId(56);
assertTrue("Command Instance ID 56 is not valid.", isValidCmdInstID == true);
isValidCmdInstID = ValidationUtility.validateCommandInstanceId(320);
assertTrue("Command Instance ID 320 is not valid.", isValidCmdInstID == true);
try
{
isValidCmdInstID = ValidationUtility.validateCommandInstanceId(0);
}
catch(BusinessObjectException b)
{
System.out.println("ValidationUtilityTest:testValidateCommandInstanceId");
}
try
{
isValidCmdInstID = ValidationUtility.validateCommandInstanceId(21);
fail("Instance ID not present.");
}
catch(BusinessObjectException b)
{
System.out.println("ValidationUtilityTest:testValidateCommandInstanceId:");
}
try
{
isValidCmdInstID = ValidationUtility.validateCommandInstanceId(-500);
fail("Invalid Instance ID.");
}
catch(BusinessObjectException b)
{
System.out.println("ValidationUtilityTest:testValidateCommandInstanceId");
}
}
public void testValidateHardwareId()throws BusinessObjectException
{
boolean isValidHardwareID = false;
isValidHardwareID = ValidationUtility.validateHardwareId("35279401003038707");
assertTrue("Hardware ID 35279401003038707 is not valid.", isValidHardwareID == true);
isValidHardwareID = ValidationUtility.validateHardwareId("357246016572305");
assertTrue("Hardware ID is not valid.", isValidHardwareID == true);
try
{
isValidHardwareID = ValidationUtility.validateHardwareId("352794010030387076546456546357567567686742324");
fail("Very Long Instance ID.");
}
catch(Exception b)
{
System.out.println("ValidationUtilityTest:testValidateHardwareId: Exception: Very Long Hardware ID.");
}
try
{
isValidHardwareID = ValidationUtility.validateHardwareId("3527dsds$$$$38707");
fail("Invalid Hardware ID.");
}
catch(Exception b)
{
System.out.println("ValidationUtilityTest:testValidateHardwareId: Exception: Invalid Hardware ID. ");
}
}
public void testValidatePanelistIDHwid()throws BusinessObjectException
{
boolean PanelistIDHwid = false;
PanelistIDHwid = ValidationUtility.validatePanelistIDHwid(19560,"A0000024B885E2");
assertTrue("Panelist ID 19560 and Hardware ID A0000024B885E2 is valid.", PanelistIDHwid == true);
//assertTrue("Hardware ID A0000024B885E2 is valid.", isValidHardwareID == true);
PanelistIDHwid = ValidationUtility.validatePanelistIDHwid(123,"357246016572305");
assertTrue("Hardware ID is not valid.", PanelistIDHwid == true);
try
{
PanelistIDHwid = ValidationUtility.validatePanelistIDHwid(19560,"352794010030387076546456546357567567686742324");
fail("Very Long Instance ID.");
}
catch(Exception b)
{
System.out.println("ValidationUtilityTest:testValidateHardwareId: Exception: Very Long Hardware ID.");
}
try
{
PanelistIDHwid = ValidationUtility.validatePanelistIDHwid(19560,"3527dsds$$$$38707");
fail("Invalid Hardware ID.");
}
catch(Exception b)
{
System.out.println("ValidationUtilityTest:testValidateHardwareId: Exception: Invalid Hardware ID. ");
}
}
}
junit.framework.AssertionFailedError: Method "testValidatePanelistIDHwid" not found
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestCase.runTest(TestCase.java:147)
at junit.framework.TestCase.runBare(TestCase.java:127)
at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:437)
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:366)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)