Helper unit testing functions in Phobos (possible std.unittests)

Masahiro Nakagawa repeatedly at gmail.com
Sat Nov 6 12:28:02 PDT 2010


On Sat, 06 Nov 2010 13:37:02 +0900, Jonathan M Davis <jmdavisProg at gmx.com>  
wrote:

> I'm proposing a possible new module for phobos which would be called
> std.unittests. The code and DDoc file can be found here:  
> http://is.gd/gLH9Q
>
> Or you can look at the code here directly (though it has poor  
> highlighting):
> http://ideone.com/EOlod
>
> The module contains a set of helper functions for unit tests which are an
> improvement over simply using assert. I have them to be very helpful in  
> the unit
> tests in my proposal for std.datetime. My unit tests are more concise,  
> easier to
> read, and much easier to debug because of them. assertEqual() and
> assertExcThrown() have been particularly useful.
>
> assert is a great tool, but simply telling you that an assertion failed  
> is not
> as useful as telling you _how_ it failed, and a function like  
> assertExcThrown()
> (which, as you may guess, asserts that a particular exception was thrown  
> by a
> particular function call) really reduces the boiler plate code that you  
> have to
> write for testing what it tests. So, I find such helper functions are  
> extremely
> useful.
>
> Because I have used them so extensively in std.datetime, they are pretty  
> much
> either going to have to be added as a module to Phobos or added as  
> private
> helper functions in std.datetime. Personally,  I think that they (or  
> something
> very similar to them) merit being added as a new module in Phobos, which  
> can be
> expanded upon as others come up with particularly useful unit testing  
> functions.
>
> So, I'm requesting that the folks here on the list have a look at my  
> module and
> review it for possible inclusion in Phobos. I don't know what Andrei's  
> position
> on them is (he rightly focused his review of my datetime code on the  
> date/time
> functionality and API rather than its unit tests and didn't mention my  
> unit
> testing functions at all), but I think that such a module would be of  
> great
> worth and would like other's opinions on it.
>
> - Jonathan M Davis

I don't know this module's usability, but is getExcMsg useful?
I can't imagine useful situation.
In addition, I grepped your datetime.d and getExcMsg not found :(

If possible, I want the mock, stub and related features.


Masahiro


More information about the Digitalmars-d mailing list