Simple bolt-on unittest improvement

Nick Sabalausky a at a.a
Fri Sep 11 21:10:21 PDT 2009


"Nick Sabalausky" <a at a.a> wrote in message 
news:h8f6pg$1q5d$1 at digitalmars.com...
> "Justin Johansson" <procode at adam-dott-com.au> wrote in message 
> news:h8edsq$b93$1 at digitalmars.com...
>>
>> The idea is to keep working within D's built in unit test facility; just 
>> don't use assert statements in current fashion as if one fails then whole 
>> test stops running.
>
> I found that to be an enormous PITA too...
>
>> I can't imagine that my approach is anything new.  What do other people 
>> do to achieve similar continuous unit testing goal?
>>
>
> Usage:
> http://www.dsource.org/projects/semitwist/browser/trunk/src/semitwist/apps/tests/deferAssertTest/main.d
>
> Implementation (incl. some extra stuff that usage app doesn't actually 
> use):
> http://www.dsource.org/projects/semitwist/browser/trunk/src/semitwist/util/deferAssert.d
>

Output from that usage app:
----------------------------------
src\semitwist\apps\tests\deferAssertTest\main.d(37): Assert Failed (foo == 3 
|| foo > 5): foo is bad
src\semitwist\apps\tests\deferAssertTest\main.d(39): Assert Failed (false)
src\semitwist\apps\tests\deferAssertTest\main.d(40): Assert Threw 
(throwsException()): Exceptions are handled:
Threw: object.Exception: Some exception
src\semitwist\apps\tests\deferAssertTest\main.d(42): Ensure Failed: ensure 
foo failed
Expression 'foo':
Expected: _ == 3 || _ > 5
Actual: 2
src\semitwist\apps\tests\deferAssertTest\main.d(44): Ensure Failed
Expression 'bar':
Expected: _ == "hola"
Actual: hello
src\semitwist\apps\tests\deferAssertTest\main.d(46): Ensure Threw: 
Exceptions are handled:
Expression 'throwsException()':
Expected: !_
Threw: object.Exception: Some exception
src\semitwist\apps\tests\deferAssertTest\main.d(47): Ensure Threw: 
Exceptions are handled:
Expression 'false':
Expected: _ == throwsException()
Threw: object.Exception: Some exception
src\semitwist\apps\tests\deferAssertTest\main.d(50): Ensure Throw Failed: 
Wrong type thrown!
Statement 'throw new Object();':
Expected: object.Exception
Actual:   object.Object: object.Object
src\semitwist\apps\tests\deferAssertTest\main.d(51): Ensure Throw Failed: 
Wrong type thrown!
Statement 'throw new Exception("Hello");':
Expected: object.Object
Actual:   object.Exception: Hello
tango.core.Exception.AssertException at src\semitwist\util\deferAssert.d(170): 
9 Assert Failures
----------------------------------





More information about the Digitalmars-d mailing list