Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>it's not right approach. You shouldn't communicate with Console in unit tests. Just extract your function which works with input parameters and test this function.</p> <p>like this:</p> <p>in YourExtractedClass:</p> <pre><code> public string GetMessage(string input) { var result = string.Empty; switch (input) { case "1": result = "Enter Account Number: "; break; case "2": result = "Hello World!"; break; default: break; } return result; } </code></pre> <p>....</p> <p>In your Test class for YourExtractedClass</p> <pre><code> [Test] public void GetMessage_Input1_ReturnEnterAccountNumberMessage() { var result = GetMessage("1"); var expected = "Enter Account Number: "; Assert.That(result == expected); } [Test] public void GetMessage_Input2_ReturnHelloWorldMessage() { var result = GetMessage("1"); var expected = "Hello World!"; Assert.That(result == expected); } </code></pre> <p>And one more thing: it's better to move you strings ("Enter Account Number" etc) to one place (fro example to some Constants class). Don't repeat yourself!</p> <p>read good books about unit testing:</p> <p><a href="http://rads.stackoverflow.com/amzn/click/1933988274" rel="nofollow">The Art of Unit Testing: With Examples in .Net</a></p> <p><a href="http://rads.stackoverflow.com/amzn/click/0977616673" rel="nofollow">Pragmatic Unit Testing in C# with NUnit, 2nd Edition</a></p> <p><a href="http://rads.stackoverflow.com/amzn/click/0131495054" rel="nofollow">xUnit Test Patterns: Refactoring Test Code</a> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload