I'm learning unit testing and wonder if this Unit test program flow (as in Arrange, Act, Assert) is correct?
[TestFixture]
public class unitTest2
{
private CoffeeMaker coffemaker;
[Test]
public void TestMethod1() // Testa metoden för kaffe med mjölk. Uppgift 2(b)
{
coffemaker = new CoffeeMaker(); //Arrange
string res = coffemaker.MakeDrink(new Coffee(true, false)); //Act
StringAssert.Contains("Coffee with milk", res); //Assert
}
}
Looks good, some minor improvements:
The Arrange/Act/Assert pattern is more visible that way. And you want to avoid anything, that's not local to your test function, because that will only cause trouble once you have a second test function.
Your function should be named "What happens and what is the expected result" because then you can see what fails in your test results. "UnitTest1 failed" is not very descriptive.