'how can i import main functin of another dart file
How can I verify that a print is called for in dart unit tests?
I am writing a sample code for textbooks and want to try it out. There are many examples that use printing for simplicity. I want to run my unit tests to make sure the print is called with the correct input but I have a problem importing the main function in another dart file.
Thank you!
Solution 1:[1]
You can import any library, including a script with a main
method. The problem is that your own script's main
method shadows the import.
The solution is to import the library with a prefix:
import "other_library.dart" as testee;
void main() {
print("Testing something");
testee.main(); // Uses a prefixed name to avoid name conflict.
print("Testing done");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | lrn |