2014-09-05 145 views
-1

我正在为以下方法编写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", ""); 
     System.out.println(str); 
    } 

//testcase. 
@Test 
public void testremoveChar() { 
    MyString test = new MyString(); 
    //what do i do next? 
} 
+1

我最近跟踪了一些你的问题,不得不建议你考虑打开一本书。通过简单地研究你的文字,你的大部分问题都可以轻松回答。获得的知识和获得的自我学习技能将直接对您未来的项目和问题有用,请相信我。 – 2014-09-05 23:43:09

回答

1

removeChar的实现可能是错误的,但这就是为什么你写一个测试没有?

我会写

 
@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); 
} 

它会失败,但是看着输出可以提高方法,直到你得到的预期。