public void testHexadecimalCheck1() { ClassName className = new ClassName(); assertEquals(true,className.hexadecimalCheck("0123456789ABCDEF"); } public void testHexadecimalCheck2() { ClassName className = new ClassName(); assertEquals(false,className.hexadecimalCheck("222222222"); }大概就是这个意思,我已经好长时间没写了,你看看吧
被测试类 /* * Created on 2003-11-24 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments *//** * @author Administrator * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class HelloWorld { public boolean hexadecimalCheck(String value) { boolean flag = true; String compare = "0123456789ABCDEF"; for (int i = 0; i < value.length(); i++) { if (compare.indexOf(value.substring(i, i + 1)) == -1) { flag = false; } } return flag; } }测试类: import junit.framework.TestCase;/* * Created on 2003-11-24 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments *//** * @author Administrator * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class HelloWorldTest extends TestCase { /** * Constructor for HelloWorldTest. * @param arg0 */ public HelloWorldTest(String arg0) { super(arg0); } public static void main(String[] args) { junit.textui.TestRunner.run(HelloWorldTest.class); } /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } public void testHexadecimalCheck() { HelloWorld hw = new HelloWorld(); TestCase.assertTrue(hw.hexadecimalCheck("0123456789ABCDEF")); } public void testHexadecimalCheck2() { HelloWorld hw = new HelloWorld(); TestCase.assertTrue(hw.hexadecimalCheck("123456789")); } }可采用 java junit.swingui.TestRunner HelloWorldTest 进行测试也可以采用 java HelloWorldTest 进行测试
{
ClassName className = new ClassName();
assertEquals(true,className.hexadecimalCheck("0123456789ABCDEF");
}
public void testHexadecimalCheck2()
{
ClassName className = new ClassName();
assertEquals(false,className.hexadecimalCheck("222222222");
}大概就是这个意思,我已经好长时间没写了,你看看吧
/*
* Created on 2003-11-24
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*//**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class HelloWorld {
public boolean hexadecimalCheck(String value)
{
boolean flag = true;
String compare = "0123456789ABCDEF";
for (int i = 0; i < value.length(); i++)
{
if (compare.indexOf(value.substring(i, i + 1)) == -1)
{
flag = false;
}
}
return flag;
}
}测试类:
import junit.framework.TestCase;/*
* Created on 2003-11-24
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*//**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class HelloWorldTest extends TestCase { /**
* Constructor for HelloWorldTest.
* @param arg0
*/
public HelloWorldTest(String arg0) {
super(arg0);
} public static void main(String[] args) {
junit.textui.TestRunner.run(HelloWorldTest.class);
} /*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
} /*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
} public void testHexadecimalCheck() {
HelloWorld hw = new HelloWorld();
TestCase.assertTrue(hw.hexadecimalCheck("0123456789ABCDEF"));
}
public void testHexadecimalCheck2() {
HelloWorld hw = new HelloWorld();
TestCase.assertTrue(hw.hexadecimalCheck("123456789"));
}
}可采用
java junit.swingui.TestRunner HelloWorldTest
进行测试也可以采用
java HelloWorldTest
进行测试