www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to do unittests

reply Namal <sotis22 mail.ru> writes:
Hello,

can someone give me a complete example please how to do 
unittests? I tried this with the example from german wikipedia, 
but the flag -unittest didn't make any difference.
Sep 30 2015
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 01/10/15 1:59 AM, Namal wrote:
 Hello,

 can someone give me a complete example please how to do unittests? I
 tried this with the example from german wikipedia, but the flag
 -unittest didn't make any difference.
Example file with loads of unittests: https://github.com/rikkimax/alphaPhobos/blob/master/source/std/experimental/uri.d If you were to compile it e.g. dmd uri.d it won't be much use (unittest wise). You will need to dmd -unittest uri.d to compile them in. Don't forget to do the same for your main function. When you run the final executable the tests will execute before your main function does.
Sep 30 2015
parent reply Namal <sotis22 mail.ru> writes:
On Wednesday, 30 September 2015 at 13:03:52 UTC, Rikki Cattermole 
wrote:
 On 01/10/15 1:59 AM, Namal wrote:
 Hello,

 can someone give me a complete example please how to do 
 unittests? I
 tried this with the example from german wikipedia, but the flag
 -unittest didn't make any difference.
Example file with loads of unittests: https://github.com/rikkimax/alphaPhobos/blob/master/source/std/experimental/uri.d If you were to compile it e.g. dmd uri.d it won't be much use (unittest wise). You will need to dmd -unittest uri.d to compile them in. Don't forget to do the same for your main function. When you run the final executable the tests will execute before your main function does.
can't I do unittest in the main?
Sep 30 2015
parent reply qsdf <qsdf qsdf.fs> writes:
On Wednesday, 30 September 2015 at 14:20:28 UTC, Namal wrote:
 On Wednesday, 30 September 2015 at 13:03:52 UTC, Rikki 
 Cattermole wrote:
 On 01/10/15 1:59 AM, Namal wrote:
 Hello,

 can someone give me a complete example please how to do 
 unittests? I
 tried this with the example from german wikipedia, but the 
 flag
 -unittest didn't make any difference.
Example file with loads of unittests: https://github.com/rikkimax/alphaPhobos/blob/master/source/std/experimental/uri.d If you were to compile it e.g. dmd uri.d it won't be much use (unittest wise). You will need to dmd -unittest uri.d to compile them in. Don't forget to do the same for your main function. When you run the final executable the tests will execute before your main function does.
can't I do unittest in the main?
D unit tests are like a stack of free functions. You put them separatly. when there's a main: dmd -unittest a.d -- module a; void main(){} unittest{} -- when there is no main: (like std.uri): dmd -main -unittest a.d -- module a; unittest{} -- the -main switch adds a dummy main function so that the output can be executed. But most of the time you'll think that nothing happens because the tests succeed...
Sep 30 2015
parent reply Namal <sotis22 mail.ru> writes:
On Wednesday, 30 September 2015 at 14:44:20 UTC, qsdf wrote:
 On Wednesday, 30 September 2015 at 14:20:28 UTC, Namal wrote:
 On Wednesday, 30 September 2015 at 13:03:52 UTC, Rikki 
 Cattermole wrote:
 On 01/10/15 1:59 AM, Namal wrote:
 Hello,

 can someone give me a complete example please how to do 
 unittests? I
 tried this with the example from german wikipedia, but the 
 flag
 -unittest didn't make any difference.
Example file with loads of unittests: https://github.com/rikkimax/alphaPhobos/blob/master/source/std/experimental/uri.d If you were to compile it e.g. dmd uri.d it won't be much use (unittest wise). You will need to dmd -unittest uri.d to compile them in. Don't forget to do the same for your main function. When you run the final executable the tests will execute before your main function does.
can't I do unittest in the main?
D unit tests are like a stack of free functions. You put them separatly. when there's a main: dmd -unittest a.d -- module a; void main(){} unittest{} -- when there is no main: (like std.uri): dmd -main -unittest a.d -- module a; unittest{} -- the -main switch adds a dummy main function so that the output can be executed. But most of the time you'll think that nothing happens because the tests succeed...
So do I understand it right that it stops after the first failed test? Is it possible to continue and get a list of all failed tests?
Oct 02 2015
next sibling parent Atila Neves <atila.neves gmail.com> writes:
On Friday, 2 October 2015 at 10:22:40 UTC, Namal wrote:
 On Wednesday, 30 September 2015 at 14:44:20 UTC, qsdf wrote:
 On Wednesday, 30 September 2015 at 14:20:28 UTC, Namal wrote:
 [...]
D unit tests are like a stack of free functions. You put them separatly. when there's a main: dmd -unittest a.d -- module a; void main(){} unittest{} -- when there is no main: (like std.uri): dmd -main -unittest a.d -- module a; unittest{} -- the -main switch adds a dummy main function so that the output can be executed. But most of the time you'll think that nothing happens because the tests succeed...
So do I understand it right that it stops after the first failed test? Is it possible to continue and get a list of all failed tests?
http://code.dlang.org/packages/unit-threaded https://github.com/D-Programming-Language/phobos/pull/3207 Atila
Oct 02 2015
prev sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, October 02, 2015 10:22:38 Namal via Digitalmars-d-learn wrote:
 So do I understand it right that it stops after the first failed
 test? Is it possible to continue and get a list of all failed
 tests?
Once a unittest block within a module has a failure in it, then no more unittest blocks within that module are run. However, unittest blocks in other modules will still be run. So, if you have failures across multiple modules, then you'll see multiple failures, but if it's just one module, then you'll only see the first one, because any further tests within the module won't even have been run. - Jonathan M Davis
Oct 02 2015