Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

Unit tests should be aware of Option Compare settings.

Open comintern opened this issue 8 years ago • 7 comments

I'd go one of two routes on this. On the one hand, we could just use the current AssertClass code and compare strings as if Option Compare Binary was set. The problem with this is that if Option Compare Text is defined in the module, the comparisons would not match the semantics of the Assert - i.e.:

Option Compare Text
'...
'@TestMethod
Public Sub TestMethod1() 'TODO Rename test
    On Error GoTo TestFail
    
    Debug.Print "FOO" = "foo"       'True
    Assert.AreEqual "FOO", "foo"    '<-- Assert fails

TestExit:
    Exit Sub
TestFail:
    Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
End Sub

If we go this route, I'd propose an inspection along the lines of OptionCompareSetInTestInspection.

The other option would be to pick up the Option Compare and use it in that Module's Asserts. I'm thinking the inspection would probably be a little easier, although either way requires determining the setting for the module.

comintern avatar Mar 14 '17 01:03 comintern