Challenge: Adding an Automated Test

Test yourself by adding an automated test.

In the following setup, we have a class called TextProcessor in the MainApp project. This class has the CountNotWhitespaceCharacters() method, which accepts a nullable string as an input parameter and returns the count of all non-whitespace characters in it. We need to write automated test scenarios for this method covering the following conditions:

  • The empty string returns zero.

  • The null input returns zero.

  • The whitespace returns zero.

  • A tab character returns zero.

  • A string with no spaces, special characters, or digits returns the value equivalent to its length.

  • A string with two words separated by a space returns the total number of letters.

  • A string with three words separated by spaces, a leading whitespace, and a trailing tab character returns the total number of letters.

All the necessary code can be added to the TextProcessorTests.cs file. While writing these test scenarios, we must adhere to the best practices. There should be no unnecessary code repetition.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy