-
Notifications
You must be signed in to change notification settings - Fork 27
Using XojoUnit
To use XojoUnit, copy the XojoUnit folder from one of the example projects to your project.
Adding your own tests is a simple process:
- Create a test class (e.g. MyTests) as a subclass of TestGroup.
- Create a subclass of TestController (e.g. XojoUnitController).
- Add your test subclass (MyTests) to the InitializeTestGroups event handler on XojoUnitController:
group = New MyTests(Self, "My Tests")
- Create methods in your test subclass class (MyTests) to do the tests. The methods must end in “Test” in order for them to appear in the XojoUnit results.
- Provide a way to display the results and run the tests. For desktop apps, you want to show the TestWindow, for web apps you want to show the TestPage and for console apps you want to run the tests manually.
A TestGroup has an Assert property that you will use test your assumptions. (See Assertions.) For example, Assert.AreEqual("xyz", TheTestedMethod)
.
There are convenience methods for gathering stats like StartTestTimer
, LogTestTimer
and GetTestTimer
that will let you record speed measurements for various parts of your code.
When you need to test some asynchronous method, e.g., a call to a web page, you can tell your test to "pause" using AsyncAwait(maxSeconds)
. Intercept the conclusion of the method and call AsyncComplete
to let the framework know that the test finished, then test the results as you normally would using Assert.
If the method does not return within the specified number of seconds, the test is considered a failure.
Note that the method that handles the method's return is outside the framework so any raised Exceptions must be handled or your test app will crash. Remember to clean up any calls to AddHandler
with RemoveHandler
.