TDD with MS Test

Like all good programmers, I try to understand some things when using TDD with MS Test. I follow the basic scheme of Arrange, Act, Assert, and something is too complicated for my Act code. I believe that there should be only one action in the line of the Law. So, given my sample code below, am I leaving the track by first performing one action, and THEN checks its status? Thanks for the input.

    [TestMethod]
    public void TheCountOfAllRecordsIsGreaterThanZero()
    {
        //Arrange
        var auditLog = new AuditMasterClass();

        //Act

        //Create a new record in a local list of objects
        auditLog.LogAction("MyPersonName", DateTime.Now, "Stuff", "MoreStuff",
                                   "Desc",
                                   "Comments", true, false,
                                   "UndoStatement");

        //Return the count of objects in the local list
        var count = auditLog.GetCommentCount();

        //Assert
        Assert.IsTrue(count > 0);
    }
+3
source share
3 answers

The test seems wonderful to me - I would not become too dogmatic, but if you feel better, you can mark the line: var count = auditLog.GetCommentCount();as part of the approval phase;)

, , - - Assert.AreNotEqual(0, count) Assert.IsTrue(count > 0, string.Format("Count was not greater than 0, it was {0}", count)) - .

+5

, . count

Assert.IsTrue(auditLog.GetCommentCount() > 0);

. , , , , LogAction() , . . , , , , . , , :

Assert.IsTrue(auditLog.GetCommentCount() == 0);

.

+5

, . , , Assert .

In the test TheCountOfAllRecordsIsGreaterThanZeroshown above, creating a new record is part of the Arrange section - or the test has the wrong name and maybe TheCountOfAllRecordsIncreasedUponLogAction.

I would also like to note that one action on a test case can mean several lines of code. The idea is not to write a whole script with a long sequence of actions.

+1
source

Source: https://habr.com/ru/post/1772682/


All Articles