Unit test class anatomy
When we unit test, we tend to write a unit test class that is targeting a parallel production class – one test class against one production class.
Applying this concept to our WFA project, our production class is WeatherForecastController
and the unit test class is going to be called WeatherForecastControllerTests
. So, rename the UnitTest1
sample class to WeatherForecastControllerTests
.
Tip
You can set your text cursor anywhere within the class name in the source code (in the previous case, it was UnitTest1
) and hit Ctrl + R, R (hold Ctrl then press R quickly twice). Type the new name WeatherForecastControllerTests
and hit Enter. This will also rename the file if the Rename symbol’s file checkbox is ticked.
Next, we will see how to organize our unit test class and its methods.
Class naming convention
I found the most commonly used convention is calling the unit test class name the same as the production code class name, appending...