Unit Testing in VB.NET
This is the simplest yet descriptive example for the unit testing procedure. Feel free to add more methods to check against different data types.
Testing Employee Class assigned and derived Properties
This example has more tests available in unit testing.
Employee.vb (Class Library)
EmployeeTest.vb (Test Project)
Result after running tests
Unit Testing for Tax Calculation
This example is divided into two pillars
- SalaryCalculation Class : Calculating the net salary after tax deduction
- SalaryCalculationTests Class : For testing the method that calculates the net salary
Step 1: Create Class Library, name it WagesLibrary or any appropriate name. Then rename the class to SalaryCalculation
''' Class for Salary Calculations
Public Class SalaryCalculation
Step 2 : Create Unit Test Project. Add reference to the created class library and paste the below code
Assert.Equal checks the expected value against the actual calculated value. the value
0.1 is used to allow tolerance or variation between expected and actual result.
Step 3 : Run the test of the method to see result
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0