On Wednesday, 24 August 2016 at 12:00:32 UTC, Andrei Alexandrescu
wrote:
On 08/24/2016 04:14 AM, Edwin van Leeuwen wrote:
I might be dense, but the only other thing than integration
tests that I
can think of is if you use random data for testing, but that
would be
more correctly solved by using more random data during the
unittests.
Nothing is worse than tests that only sometimes fail.
Randomized unit testing is a respected approach to testing:
https://hackage.haskell.org/package/QuickCheck,
https://github.com/rickynils/scalacheck,
https://blogs.msdn.microsoft.com/dsyme/2008/08/08/fscheck-0-2/,
etc. Some of the Phobos tests I wrote use it (and virtually all
of my current code e.g. on median computation), and when they
fail I just print the seed of the RNG and then hardcode it to
reproduce the test. -- Andrei
unit-threaded has had QuickCheck-like property-based testing
features for a while now. As mentioned previously in the forum, I
wrote this test in cerealed:
@Types!(bool, byte, ubyte, short, ushort, int, uint, long, ulong,
float, double,
char, wchar, dchar,
ubyte[], ushort[], int[], long[], float[], double[])
void testEncodeDecodeProperty(T)() {
check!((T val) {
auto enc = Cerealiser();
enc ~= val;
auto dec = Decerealiser(enc.bytes);
return dec.value!T == val;
});
}
Checks that for every type in the list that given a random value
of that type, serialising then deserialising should yield the
same value back.
Atila