Tangara G

Tangara G

  • 1.8k
  • 298
  • 76.2k

Why this unit test failed etc?

Sep 10 2020 10:16 PM
I have this method :
  1. private bool MatchedTarget(string TargetName, Paragraph paragraph, string text)  
  2. {  
  3.     bool targetFound = false;  
  4.     if (IsHeader(paragraph)) {  
  5.         text.ToLower().Trim().Contains(TargetName.ToLower().Trim());  
  6.         targetFound = true;  
  7.     }  
  8.     return targetFound;  
  9. }  
And I have a unit test but it returned me Failed where it is supposed to return Passed.
 
Please let me know where I had gone wrong
  1. [Test]  
  2. public void LowerCaseShouldReturnTrue()  
  3. {  
  4.     ProcessingDocx processor = new ProcessingDocx(null);  
  5.     Paragraph para = CreateParagraphStyle("Normal");  
  6.   
  7.     System.Type type = typeof(ProcessingDocx);  
  8.     bool result = (bool)type.GetMethod("MatchedTarget", BindingFlags.NonPublic | BindingFlags.Instance)  
  9.                             .Invoke(processor, new object[] { "Annex A",  para, "annex a" });  
  10.   
  11.     Assert.True(result);  
  12. }

Answers (6)