2014-02-25 99 views
1

我在寫一組簡單的單元測試。在這個特定的測試中,我正在測試所有標準文本輸入到函數中。C#單元測試。並非所有的路徑都返回值

然而,當我嘗試編譯,我收到此錯誤

ConverterTests.ConvertSixteenthsFractionalToDecimal_AverageCase()':不是所有的代碼路徑返回一個值

我應該改變來解決這個編譯錯誤?

下面是代碼:

 [TestMethod] 
     public double ConvertSixteenthsFractionalToDecimal_AverageCase() 
     { 
      // arrange 
      string input = "1/16"; 
      int expected = 1; 
      // act 
      int actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "1/8"; 
      expected = 2; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 


      // arrange 
      input = "3/16"; 
      expected = 3; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "1/4"; 
      expected = 4; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "5/16"; 
      expected = 5; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "7/16"; 
      expected = 3; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "1/2"; 
      expected = 8; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "9/16"; 
      expected = 9; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "5/8"; 
      expected = 10; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "11/16"; 
      expected = 11; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "3/4"; 
      expected = 12; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "13/16"; 
      expected = 13; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "7/8"; 
      expected = 14; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

      // arrange 
      input = "15/16"; 
      expected = 15; 
      // act 
      actual = clsDimension.CvtSixteenthsFractionalToDecimal(input); 
      // assert 
      Assert.AreEqual(expected, actual); 

     } 

回答

9
public double ConvertSixteenthsFractionalToDecimal_AverageCase 

應該

public void ConvertSixteenthsFractionalToDecimal_AverageCase 

測試方法沒有返回值。

順便說一句:

這是不是你寫一個很好的測試,每次安排,行爲,主張應該是它自己的測試情況下,否則在一個失敗將阻止所有其他從跑步。

+0

我在12分鐘內接受 –

+0

對不起,我分心了,從未回來 –

相關問題