Jonathan M Davis napisał: > 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.
If the language can't help, helpers are definitely of value. In Java I rarely use the built-in assert statement and resort to JUnit functions where possible. > 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. >From a different angle: if assert is already part of the language, and the >compiler has access to the AST of the tested expression, perhaps it could also automatically generate code that pretty-prints the expression? -- Tomek