Assert.IsTrue



  • Some people do not like mstest because it is so basic and hardly provides functionality...
    Well, Bernie's coworker Kevin and David actually could do with an even more basic unit test suite:

    Assert.IsTrue(connectionGuard.ConnectionStatus == ConnectionStatus.Connected);
    Assert.IsTrue(connectionGuard.ConnectionStatus == ConnectionStatus.Disconnected);
    Assert.IsTrue(tableNames.Contains("somename"));
    Assert.IsTrue(dataFieldDefinition.FieldName == "TestName" && dataFieldDefinition.FieldType == typeof(DateTime) && dataFieldDefinition.IsKey);
    Assert.IsTrue(dataFieldDefinitions.Contains(dataField.FieldDefinition));
    Assert.IsTrue(blobValue[0] == 1 && blobValue[1] == 2 && blobValue[2] == 3 && blobValue[3] == 4 && blobValue[4] == (byte)intValue);
    Assert.IsTrue(tempRange.Minimum == dummyTempRanges[tempRangeIdx].Item1 && tempRange.Maximum == dummyTempRanges[tempRangeIdx].Item2);
    

    Why do you need

    Assert.AreEqual
    CollectionAssert.Contains
    

    or even the extensions Bernie wrote like

    AssertExtensions.IsGreaterThan
    AssertExtensions.IsLessThan
    

    when you can reduce everything to a simple Assert.IsTrue?



  • @berniethebernie said in Assert.IsTrue:

    Assert.IsTrue(connectionGuard.ConnectionStatus == ConnectionStatus.Connected);
    Assert.IsTrue(connectionGuard.ConnectionStatus == ConnectionStatus.Disconnected);

    Schrödinger's connection?


  • Discourse touched me in a no-no place

    @homobalkanus I don't think the code sample includes the lines between…

    (Also, if this was Python — it isn't of course, I know, I know — then just using assert would be reasonable; at least one test suite runner can drill down into the expression that produced the assertion failure anyway and that's pretty nice. One of the best things about the language…)



  • @berniethebernie Syntactic sugar. And the failure messages are tailored to the specific asserts: Assert.AreEqual(foo, <stuff to test>) produces something like "Assert.AreEqual failed: expected foo, actual bar".


  • 🚽 Regular

    @khudzlin Did you answer a rhetorical question?



  • @zecc said in Assert.IsTrue:

    @khudzlin Did you answer a rhetorical question?

    Probably 2 in this thread now.


Log in to reply