Parametrized vs. Nonparametrized Tests
Learn the difference between parametrized and nonparametrized tests in xUnit.
In this lesson, we’ll learn the difference between parametrized and nonparametrized tests. We’ll also learn the best practices for using either of these. We will do so with the help of the following playground:
namespace MainApp; public class Calculator { public int MultiplyByTwo(int value) { return value * 2; } }
In this playground, we use the MainApp
project that represents our assembly under test. The project has the Calculator
class with the MultiplyByTwo()
method. The method multiplies the input parameter by 2
and returns the result. All our tests cover this method.
Nonparametrized tests
Nonparametrized tests in xUnit are represented by methods marked with the Fact
attribute. These methods don’t accept any parameters, and each of such methods represents a single test. We can find an example of this in the CalculatorTests.cs
file inside the MainApp.Tests
project of the above playground. The Fact
attribute can be found on line 5.
Everything is hard-coded because we don’t have any parameters in this ...