Skip to content

WUnit Wollok Unit Testing

Fernando Dodino edited this page Aug 31, 2019 · 11 revisions

The whole flow of testing begins when a user requests a .wtest file to be tested:

Tests

First part: launching tests

Wollok_Testing_Launch

Before Wollok Launcher starts, we need to setup some things: WollokLauncherParameters object has

  • a tests flag pointing to true value
  • and a testPort number
    • WollokTestLaunchDelegate sets testPort to WollokContextStateNotifier.listeningPort, from the UI-VM

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

Second part: Wollok Launcher

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

Third part: test reporter notification

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:

Clone this wiki locally