Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Rubberduck unit tests, how can I find out which one of multiple asserts failed?

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.

like image 449
Jörg Brenninkmeyer Avatar asked Apr 06 '17 19:04

Jörg Brenninkmeyer


1 Answers

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

like image 54
Mathieu Guindon Avatar answered Oct 21 '22 03:10

Mathieu Guindon