Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Dunit Filters

Dunit features some filters to add functionality to tests, using the following format:

tests["name"] = filter =
{
	/* test */
};

expectedException

This test should throw an exception of a particular type (or subclass of that type). Throwing no exception is an error. Throwing a different type of exception is an error. Throwing an exception of the requested type is not an error.

tests["throw an exception"] = expectedException!(MyException) =
{
	// The exception is thrown, so the test succeeds.
	throw new MyException();
};
tests["no exception"] = expectedException!(MyException) =
{
	// I'm not throwing an exception, so this test fails.
};
tests["wrong exception"] = expectedException!(MyException) =
{
	// I'm throwing the wrong type of exception, so this test still fails.
	throw new AbandonedMutexException();
};

parameters

Tests usually have to take no arguments. The parameters filter allows you to have tests that take arguments. Currently, this only allows one-argument tests.

tests["parameters"] = parameters("hello", "goodbye", "strom thurmond") =
(char[] name)
{
	assert (name != "strom thurmond");
};