VB.NET and NUnit - TDD

I am learning TDD with VB.NET and NUnit. I want to know what is best to do: Use many Assert methods inside a test method or use assert for a method?

This is my code. Thank.

Imports NUnit.Framework

<TestFixture()> _
Public Class CalculatorTest
<Test()> _
Public Sub TestAdd()
    Dim calculator As Calculator = New Calculator()

    Assert.AreEqual(2, calculator.sum(1, 1))
    Assert.AreNotEqual(3, calculator.sum(2, 2))
    Assert.AreEqual(-1, calculator.sum(0, -1))
        Assert.AreNotEqual(3, calculator.sum(1, 1))
    End Sub
End Class
+5
source share
4 answers

The best way to think about this is to check one thing at a time. Use as many statements as necessary to verify this, but usually only one. Several statements may be a sign that you are testing several pieces at the same time, but this, in my opinion, is not a very strict rule. The best guide is that you do not want to create dependencies in your tests between independent concepts.

4 , , , , . , , , . (). , - .. , , .. , , ; , , , , .

- , , "" - , , ​​ . , , . , , - , , , .

+7

" " - . ( )

NUnit TestCases:

<Test()> _
<TestCase(1, 1, 2)> _
<TestCase(1,-1, 0)> _
<TestCase(0,-1,-1)> _
Public Sub Calculator_Add_ReturnsExpectedResult(Integer a, Integer b, Integer expected)
    Dim calculator As Calculator = New Calculator()

    Assert.AreEqual(expected, calculator.sum(a, b))
End Class

, , , .

" " , , - . , , .

+5

. , unit test.

.

.

0

. , /, , , assert, .

, . , , "".

0

All Articles