8

I'm using Rubberduck to unit test my VBA implementations. When using multiple Asserts of the same kind (e.g. Assert.IsTrue) in one TestMethod, the test result is not telling me which of them failed, as far as I can see.

Is there a way to find out which Assert failed or is this on the Rubberduck future roadmap? Of course I could add my own information, e.g. by using Debug.Print before each Assert, but that would cause a lot of extra code.

I know there are different opinions about multiple Asserts in one test, but I chose to have them in my situation and this discussion is already covered elsewhere.

Community
  • 1
  • 1
Jörg Brenninkmeyer
  • 3,304
  • 2
  • 35
  • 50

1 Answers1

7

Disclaimer: I'm heavily involved in Rubberduck's development.

The IAssert interface that both the Rubberduck.AssertClass and the Rubberduck.PermissiveAssertClass implement, includes an optional message parameter for every single member:

Object Browser showing members of 'AssertClass'

Simply include a different and descriptive message for each assertion:

Assert.AreEqual expected, actual, "oops, didn't expect this"
Assert.IsTrue result, "truth is an illusion"

The Test Explorer toolwindow will display the custom message under the Message column, only when the assertion fails:

RD Test Explorer

Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
  • 1
    Very helpful - I suggest to add this to the [Wiki on Rubberduck Unit Testing](https://github.com/rubberduck-vba/Rubberduck/wiki/Unit-Testing). – Jörg Brenninkmeyer Apr 06 '17 at 19:49
  • 4
    @JörgBrenninkmeyer OMG these shots are from 1.4! The wiki definitely needs a bit of revamping... especially with the changes coming to the testing framework next release (did I say *mocking*?)... – Mathieu Guindon Apr 06 '17 at 19:53
  • @Mat'sMug Now that there's a rubberduck tag, do you want to encourage people to include their current version number in their Rubberduck questions? This question and your answer are version agnostic, but now you've made non-version agnostic comments and other questions may not be version agnostic. – puzzlepiece87 Apr 07 '17 at 18:41
  • @puzzlepiece87 the tag has been around for a while (see my meta.SO questions) - indeed it would be nice if askers included a build#... but not quite mandatory I think. Common RD questions that are specific to one particular release will not likely be asked or even researched by users of later releases. Answers OTOH, should at least hint at the current latest version though. – Mathieu Guindon Apr 07 '17 at 18:47