-
Notifications
You must be signed in to change notification settings - Fork 16
WUnit Wollok Unit Testing
The whole flow of testing begins when a user requests a .wtest
file to be tested:
Before Wollok Launcher starts, we need to setup some things: WollokLauncherParameters object has
- a
tests
flag pointing totrue
value - and a
testPort
number-
WollokTestLaunchDelegate sets
testPort
toWollokContextStateNotifier.listeningPort
, from the UI-VM
-
WollokTestLaunchDelegate sets
WollokLauncherModule
has sets the test reporter to the corresponding one:
-
WollokRemoteTestNotifier
if launcher was run from Wollok IDE -
WollokConsoleTestsReporter
if launcher was run from wollok-cli
Wollok Launcher calls Wollok Interpreter which in turn calls to the WollokInterpreterEvaluator | WollokLauncherInterpreterEvaluator
.
WollokInterpreterEvaluator delegates to several dispatch methods, but one of them is the main for tests/suites: WollokLauncherInterpreterEvaluator.evaluate(WFile)
. If you need to change the way tests are evaluated, this is the right place. Take a look into SuiteBuilder
class.
override dispatch evaluate(WTest test) {
try {
test.elements.forEach [ expr |
interpreter.performOnStack(expr, currentContext) [ | expr.eval ]
]
wollokTestsReporter.reportTestOk(test)
null
} catch (Exception e) {
handleExceptionInTest(e, test)
}
}
protected def WollokObject handleExceptionInTest(Exception e, WTest test) {
if (e.isAssertionException) {
wollokTestsReporter.reportTestAssertError(test, e.generateAssertionError, e.lineNumber, e.URI)
} else {
wollokTestsReporter.reportTestError(test, e, e.lineNumber, e.URI)
}
null
}
- Every time a test passes, test reporter is notified (testOk)
- The same happens if a test has an assertion error or fails
- There are a lot of notifications for the test reporter inside WollokLauncherInterpreterEvaluator
WollokRemoteTestReporter
collects every test result until the whole testing process finishes:
override finished(long timeElapsedInMilliseconds) {
if (!processingManyFiles) {
remoteTestNotifier.testsResult(testsResult, timeElapsedInMilliseconds)
}
}
remoteTestNotifier
is an instance variable, pointing to WollokRemoteUITestNotifier
interface.
Remember, you are still in the launcher VM: