Unit testing a function returning void
Bruno Pagis
imnotsharing at myaddress.com
Thu Nov 3 10:00:27 UTC 2022
Good morning,
I have the following class:
```
class A {
int[] array;
...
void print() {
writeln("array = ", this.array);
}
}
```
I would like to unit test the print function (yes, I know, not
very useful on the above example since print is merely a
duplicate of writeln...). Is there a way to use assert to test
the output of the print function to stdout? Something like:
```
A myClass= new A;
myClass.array = [1,2];
assert(myClass.print() == "array = [1,2]"); // I know that print
does not return anything so this is wrong, but you get the idea
:-)
```
Thanks.
More information about the Digitalmars-d-learn
mailing list