当前位置: 技术问答>java相关
谁有Junit测试一个类的例子,给兄弟一个,跟贴有分
来源: 互联网 发布时间:2017-04-09
本文导语: 最近要搞项目测试,哪位做过给兄弟点代码,最好测试类和被测试类越简单越好,比如说我测试下面一个类: //被测试类 public class { public get_hello(){ return "hello"; } } Junit测试工具,这个类的测试类该怎么写,欢迎...
最近要搞项目测试,哪位做过给兄弟点代码,最好测试类和被测试类越简单越好,比如说我测试下面一个类:
//被测试类
public class {
public get_hello(){
return "hello";
}
}
Junit测试工具,这个类的测试类该怎么写,欢迎跟贴,up有分
//被测试类
public class {
public get_hello(){
return "hello";
}
}
Junit测试工具,这个类的测试类该怎么写,欢迎跟贴,up有分
|
import junit.framework.*;
public class HelloTest extends TestCase{
public void testGetHello(){
Hello aHello = new Hello();
String strExpected = "hello";
assertEquals(aHello.getHello(),strExpected);
}
}
public class HelloTest extends TestCase{
public void testGetHello(){
Hello aHello = new Hello();
String strExpected = "hello";
assertEquals(aHello.getHello(),strExpected);
}
}
|
"HelloTest.java": Error #: 307 : constructor TestCase() is not public in class junit.framework.TestCase; cannot be accessed from outside package at line 6, column 8
if a class'constructor is not public,then the class can't be extended or provide the static factory method.
so you must be modify the source code of junit.
if a class'constructor is not public,then the class can't be extended or provide the static factory method.
so you must be modify the source code of junit.
|
你可以用jbuilder自动生成一个,file-->new-->test
|
public class HelloTest extends TestCase{
public void testGetHello(){
Hello aHello = new Hello();
String strExpected = "hello";
assertEquals(aHello.getHello(),strExpected);
}
}
up
public void testGetHello(){
Hello aHello = new Hello();
String strExpected = "hello";
assertEquals(aHello.getHello(),strExpected);
}
}
up
|
跟贴有分 --->>>> up
|
UP
|
跟贴有分 --->>>> up
|
up
|
up
|
呵呵,就等着收分啦~
|
up