開発を駆動する方法のテスト


詳細
需要:文を反転
次のテストを書くかもしれません.テストを書いて、コードを書いてテストを合格させ、次のテストを書きます.
自分で見ましょう.
public class StringReverseTest {  
  # Test 1
  public void testShouldSplitSentenceIntoWords(){  
    StringReverser sr=new StringReverser();  
    String str = "This is a sentence";  
    Assert.assertEquals(4, sr.split(str).size());
    Assert.assertEquals("sentence", sr.split(str).get(0));  
    Assert.assertEquals("a", sr.split(str).get(1));  
    Assert.assertEquals("is", sr.split(str).get(2));  
    Assert.assertEquals("This", sr.split(str).get(3));  
  }  
  # Test 2
  public void testShouldReverseSentence(){  
    StringReverser sr=new StringReverser();  
    String str = "Tdd is a software devolopment technology";  
    Assert.assertEquals("technology devolopment software a is Tdd",sr.reverse(str));  
  }  
  # Test 3
  public void testShouldAlwaysReverseSentences(){  
    StringReverser sr=new StringReverser();  
    String str = "This is Yet Another sentence";  
    Assert.assertEquals("sentence Another Yet is This",sr.reverse(str));  
  }  
}