How to download and configure the project?
To start working on your own unit tests, you must first download the base project from GitHub, a crucial step for developers looking to delve into the creation of string manipulation libraries in .NET. In the GitHub repository, provided in the course resources, you'll find two branches: master
and codebase
. Both contain the same clean project to implement tests, but without examples or pre-existing tests.
How to download the project?
- Clone the repository: If you want to work directly from a version-controlled environment, use
git clone
to get the repository on your local machine.
- Download as a .zip file: For those who prefer to handle files manually, there is the option to download the project as a compressed file.
- Create a new repository: Regardless of the download method, it is recommended to create a new repository on your personal GitHub to store your progress and customizations.
How to structure the project in Visual Studio?
With the project already downloaded, the next step is to open it in Visual Studio, where you can explore its structure. The project is known as "StringManipulation" and contains the main class "StringOperation", which in short, acts as a library of utilities for manipulating strings.
What functions does the StringOperation library include?
- Concatenate: Allows to join several strings into one.
- Reverse: Reverses the order of characters in a string.
- GetStringLength: Returns the length of a string.
- RemoveWhiteSpaces: Removes whitespaces in a string.
- TruncateString: Truncates a string by the maximum number of characters specified.
- Palindrome detection: Checks if a word is a palindrome.
- Occurrences of a character: Counts how many times a specific character appears in a string.
- Pluralize: Converts a singular word to its plural form.
- QuantityInWords: Converts numbers within a sentence to words.
- Roman numerals: Converts Roman numerals to integers.
- Read String from file: Allows to load the content of a file as a string.
Examples of use in the Program class
The "Program" class allows executing and testing the operation of the library functions. It is not only a utility for testing, but also provides a point of interaction for the user:
- TruncateString: executes the function by entering a string and a maximum number of characters. For example, entering "Hello everyone from Platzi" with a maximum of 6 characters returns "Hello and".
- Pluralize Word: Transforms words such as "Card" and "City", displaying their plural form as "Cards" and "Cities", respectively.
- Roman numerals: Converts Roman numerals such as "VI" to the number 6.
How to perform unit tests with XUnit?
The next step is to test these functions by creating our own unit tests. XUnit is a popular and easy-to-use testing framework in .NET:
- Identify test scenarios: Develop different test cases for each function, making sure to cover the broad spectrum of possibilities and verify that the functions behave properly.
- Build and run: Use XUnit to write, run and validate your test results.
Encourage students to explore and strengthen their programming skills by practicing creating tests under various conditions. This will give you an excellent opportunity to discover how each feature can be integrated into larger applications, extending functionality and bringing improvements to a project. Go ahead, continue your learning, testing and development has never been so exciting!
Want to see more contributions, questions and answers from the community?