Domanda

I know D has built-in unit tests, but while they are incredibly useful, they are also very limited, especially when reporting errors. I've been looking at third party tool kits and frameworks, and can't seem to decide between them.

What is the low down about unit testing D programs?

È stato utile?

Soluzione 2

Most everyone just uses the built-in unit testing framework. And if what you're doing is unit testing, it's generally plenty. It's when you're doing more complicated testing - testing beyond making sure that each individual function has the correct output for various inputs - that the built-in unit testing might not be enough - or at least it doesn't provide additional tools to support fancier tests. However, it does provide enough to build more complicated testing tools if you want them. Given that unittest blocks are essentially just normal functions that get called when the tests are run and given how D has fantastic compile-time reflection, you can do a lot inside of a unittest block. There just aren't many testing-specific tools provided by the language or standard library. The few that there are can be found in std.exception - e.g. assertThrown and assertNotThrown.

Now, there are folks who think that the built-in unit testing facilities are lacking or who just don't like how they work for one reason or another, so several homegrown unit testing frameworks have been created by folks in the community (many of which - as DejanLekic points out - can be found on the D wiki), but at this point, most everyone just uses the built-in unit testing facilities.

EDIT: As Михаил Страшун points out, std.typecons does have basic some facilities for mocking objects if you're looking for something along those lines. e.g.

http://dlang.org/phobos/std_typecons.html#.AutoImplement http://dlang.org/phobos/std_typecons.html#.BlackHole http://dlang.org/phobos/std_typecons.html#.WhiteHole

They're excellent examples of what D's compile-time reflection can do and can be used with D's built-in unit testing facilities without needing anything more complicated added to the language or requiring a separate framework.

Altri suggerimenti

If you are not happy about the way unit-tests are done in D, there are few testing frameworks for D available. Most of them are listed on D wiki: http://wiki.dlang.org/Libraries_and_Frameworks#Unit_Testing_Framework .

Dicebot caught me on IRC and we had a lengthy talk about testing D programs. The gist was that there's a very strong focus in the D community about sticking to the built in testing facilities, and that most unit test frameworks go largely unused. In his own words:

Anything more fancy than assert helpers I would probably not recommend (like not-fatal assertions or using classes as test blocks), but within just tweaking printed messages, feel free to experiment.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top