Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 10, 2007 Question about unittests | ||||
---|---|---|---|---|
| ||||
I was looking at the spec and it mentions that "unittest" is a special method in classes. Can you have more than one unittest method in a class? |
January 10, 2007 Re: Question about unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to mfeathers | mfeathers wrote:
>
> I was looking at the spec and it mentions that "unittest" is a special method in classes.
>
> Can you have more than one unittest method in a class?
>
Unittests are actually not methods inside classes, but more statement blocks that are executed when you compile & execute unittests. So, they work as if you provide a void main () {} in every file/class/whatever scope you put them in.
And yes, IIRC, you can have multiple unittest blocks per file, too. Though, they are all executed then. You could workaround that with version() { } blocks.
|
January 10, 2007 Re: Question about unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexander Panek |
Thanks. Another quick question. Is "assert" legal syntax outside of contacts and unit tests? For instance, can I do this:
unittest {
someMethod();
}
void someMethod() {
assert 0 == 1
}
Michael Feathers
Alexander Panek wrote:
> mfeathers wrote:
>
>>
>> I was looking at the spec and it mentions that "unittest" is a special method in classes.
>>
>> Can you have more than one unittest method in a class?
>>
>
> Unittests are actually not methods inside classes, but more statement blocks that are executed when you compile & execute unittests. So, they work as if you provide a void main () {} in every file/class/whatever scope you put them in.
>
> And yes, IIRC, you can have multiple unittest blocks per file, too. Though, they are all executed then. You could workaround that with version() { } blocks.
|
January 10, 2007 Re: Question about unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to mfeathers | mfeathers wrote: > > Thanks. Another quick question. Is "assert" legal syntax outside of contacts and unit tests? For instance, can I do this: > > unittest { > someMethod(); > } > > void someMethod() { > assert 0 == 1 > } assert(0 == 1);, but otherwise yes. -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi Dancing the Tango |
January 10, 2007 Re: Question about unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to mfeathers | mfeathers escribió:
>
> Thanks. Another quick question. Is "assert" legal syntax outside of contacts and unit tests? For instance, can I do this:
>
> unittest {
> someMethod();
> }
>
> void someMethod() {
> assert 0 == 1
> }
Yes. Asserts are always evaluated if you provided -debug to the compiler. Of course for asserts in unittests to work you also have to provider -unittest to the compiler.
|
January 11, 2007 Re: Question about unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ary Manzana | Reply to Ary,
> mfeathers escribió:
>
>> Thanks. Another quick question. Is "assert" legal syntax outside of
>> contacts and unit tests? For instance, can I do this:
>>
>> unittest {
>> someMethod();
>> }
>> void someMethod() {
>> assert 0 == 1
>> }
> Yes. Asserts are always evaluated if you provided -debug to the
> compiler. Of course for asserts in unittests to work you also have to
> provider -unittest to the compiler.
>
asserts are active unless you give the -release flag, even without the -debug flag
|
Copyright © 1999-2021 by the D Language Foundation