OCaml Forge

Detail: [#1261] Adding non-fatal assertions

Feature Requests: Browse | Download .csv | Monitor

[#1261] Adding non-fatal assertions

2013-03-02 23:11
Submitted by:
Thomas Wickham (mackwic)
Assigned to:
Sylvain Le Gall (gildor-admin)
Operating System:
Adding non-fatal assertions

Detailed description
Asserts are fatals, that is, if we put multiple asserts that fails in one test, the runner stops at the first failing assert.

However, when a test fails, don't we want all possible information ?

Nowadays, the workaround is to split our test in multiples assertions, and that's a good thing to promote shorts and readable tests.
The sad thing is, it's not always very clever ie for one pure functional action, if we want to have multiple asserts and multiple outputs in case of failure, we duplicate the code and change only the assert. That's bad.

My request is to add non-failure asserts, as Google Tests do with their EXPECT_* tests. ( http://code.google.com/p/googletest/wiki/Primer#Assertions )

Theses tests act as normal asserts in all ways but :
- If they fails, the runner continue to eval the other asserts
- If at least one 'expect_' fail, the test is failed
- If we meet an assert that fails, we obviously don't go ahead even if there are only 'expect_' on our way

From an implementation point of view, this implies that Exceptions can't be used anymore.
A simple way would be to initialize a global state in OUnitCore.perform_test. That's not shocking but it's disappointing to going out of the functional paradigm only for that.

An other way would be to separate the action we want to test and the post-conditions it have to meet. It's far more flexible from the runner point of view but implies that 1) we'll broke the existing paradigm of OUnit and 2) we can't put expects in the middle of an action.

I like the second method. It's the way I use to write tests, but that's only how I see things.


Date: 2013-09-30 00:40
Sender: Sylvain Le Gall

Close with OUnit v2.0.0.
Date: 2013-03-03 19:58
Sender: Sylvain Le Gall

Works for me but only for OUnit 2.

I plan to provide a "state" parameter to test functions that should be used to log and will also allow to do this kind of non-fatal assertion.

Attached Files:


Field Old Value Date By
status_idOpen2013-09-30 00:40gildor-admin
close_dateNone2013-09-30 00:40gildor-admin
assigned_tonone2013-03-03 19:58gildor-admin