Data-drive (aka table-driven) tests

Russel Winder via Digitalmars-d digitalmars-d at puremagic.com
Fri Dec 4 10:49:39 PST 2015


Is anyone looking at enabling proper data-driven tests by example.
Trivial example: Factorial implementations, you just want to write a
few examples in a table and have the compiler test them all
individually with all being tested even if some fail. In languages that
have assertions with termination semantics this is impossible to do
with loops. Languages like Go have a test framework with no assertions
per se just tools for reporting an error: in Go table driven testing is
trivially easy. In Python, at least using PyTest, there is the
@pytest.mark.parametrize decorator that writes separate functions for
each data item given the test function template. This works very nicely
with the Python approach of terminating assertions since on execution
there is a test function per test case from the table.

I am finding that although this can be done trivially in dynamic
languages, in static languages it is less so. Scala can do it due to
the language semantics and macros. Rust cannot do it yet, the macro
system isn't up to it. What about D? Has anyone tinkered with this?

As an ancillary question: has anyone got a property-testing framework
in D. The original is from Haskell, QuickCheck. Ceylon and similar
languages have a pale imitation, Rust has the real thing.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20151204/0e5947fa/attachment.sig>


More information about the Digitalmars-d mailing list