Java void方法的Junit测试用例
我正在为以下方法编写Junit测试用例。Junit测试用例在下面。我似乎不知道该测试什么或如何测试Java void方法的Junit测试用例,java,unit-testing,junit,Java,Unit Testing,Junit,我正在为以下方法编写Junit测试用例。Junit测试用例在下面。我似乎不知道该测试什么或如何测试 //method package try.out; public class MyString implements MyStringInterface{ public static String str; public void removeChar(char C){ str = MyString.str.replace("C", "");
//method
package try.out;
public class MyString implements MyStringInterface{
public static String str;
public void removeChar(char C){
str = MyString.str.replace("C", "");
System.out.println(str);
}
//testcase.
@Test
public void testremoveChar() {
MyString test = new MyString();
//what do i do next?
}
removeChar的实现可能是错误的,但这就是为什么要编写一个测试no 我会写 @Test public void testremoveChar() { MyString test = new MyString(); MyString.str = "This is a Complete Test"; test.removeChar('T'); assertEquals("his is a Complete est", MyString.str); } @试验 public void testremoveChar(){ MyString test=新MyString(); MyString.str=“这是一个完整的测试”; 测试。移除向量('T'); assertEquals(“his是一个完整的est”,MyString.str); }
<>它会失败,但是看看输出,你可以改进方法直到你得到预期。我最近跟踪了你的一些问题,并建议你考虑打开一本书。你的大多数问题都可以简单地通过学习课文来回答。相信我,所获得的知识和自学技能将对你未来的项目和问题直接有用。