Repository navigation
Releases
Releases · rubberduck-vba/RDCore.UnitTesting
RDCore.UnitTesting v0.1.0-alpha
The first prerelease of RDCore.UnitTesting: unit tests for RD-VBA code, run by an RDCore platform's UnitTesting extension from the command line. It runs on RDCore.SDK 0.2.8-alpha and needs an rdc of RDCore v0.2.10-alpha or later. This tag also publishes the RDCore.UnitTesting.Protocol package.
Warning
This is an alpha prerelease, for evaluation. Expect rough edges, and expect things to change between versions.
Writing tests
- Test modules:
'@TestModuleon a standard module makes it a test module, and'@TestMethodon a publicSubof it makes theSuba test. The platform completes and describes the test annotations. - The
RDTestlibrary and itsAssertmodule:IsTrue,IsFalse,IsNothing,IsNotNothing,AreEqual,AreNotEqual,AreSame,AreNotSame,SequenceEquals,NotSequenceEquals,Succeed,InconclusiveandFail, each with an optional message. A project uses it with a reference toRDTest.AreEqualcompares as the=operator does, with the calling module'sOption Compare, andAreSameasIsdoes. A failure says what was expected and what the run had, in English or French. - Setup and cleanup:
'@ModuleInitializeruns once before a module's tests,'@TestInitializeand'@TestCleanuparound each test (the cleanup whatever the outcome), and'@ModuleCleanuponce after them. They run from outside their module, so they arePublic(RDT00009). A'@ModuleInitializeor'@TestInitializethat is notPublicfails the module's tests, saying why. A'@TestCleanupthat is notPublicfails each test it follows that had passed, and a'@ModuleCleanupthat is notPublicdoes not run. '@ExpectedError(n): a test passes when it raises error n, and fails when it raises another error or none.'@TestCaserows: each row runs the test once with its values, as a run of its own. A row whose values do not convert to the test's parameter types fails with error 13.'@IgnoreTest: the test does not run: its outcome is Ignored, which the summary counts as skipped.
Running tests
rdc test <workspace>: runs the workspace's tests and writes a line per test run (its outcome, its name, where it failed and why), then a summary linePassed: n, Failed: n, Skipped: n, where Skipped counts the ignored and the inconclusive tests. The exit code is 0 when every test ran without failing, 1 when one failed, and 2 for arguments it does not take.--report junit <path>: also writes the results as a JUnit XML file, which CI systems read. A relative path is relative to the folderrdcruns in.- Sessions: each test module runs in a run session of its own project. An error a test does not handle fails that test, and the next test runs in the same session, with the module-level state the earlier tests left. Only an
Endstatement resets the session, and the module is initialized again before its next test. A cancel ends the whole run. - Where a test failed: a failed
Assertis located at its call, and an error at the line that raised it, in that line's own module ([Calculator:10]for an error in a procedure the test called).
Diagnostics
A test that cannot run is reported in the editor, each code with its page in English and in French:
| Code | Reported when |
|---|---|
| RDT00001 | A test is not a Sub. |
| RDT00002 | A test has parameters and no '@TestCase rows. |
| RDT00003 | A '@TestCase row's arity is not the test's. |
| RDT00004 | A test is outside a test module. |
| RDT00005 | Two or more procedures of a module have the same setup or cleanup annotation. |
| RDT00006 | '@ExpectedError is not on a test. |
| RDT00007 | '@ExpectedError names no run-time error's code. |
| RDT00008 | The test handles the error it expects. |
| RDT00009 | A test, or a setup or cleanup procedure, is Private or Friend. A procedure with no access keyword is Public, and is not reported. |
RDT00009 is a warning, with a quick fix: Make '<name>' Public writes Public in place of Private or Friend.
The extension and its package
- The extension:
PublishExtension.ps1publishes RDCore.UnitTesting into a platform'sExtensionsfolder, and the language server starts it beside its other extensions. The extension builds from its source at this tag. - The RDCore.UnitTesting.Protocol package on NuGet: the names of the test annotations (
TestAnnotations) and theRDTdiagnostic codes (TestDiagnostics), for a client that works with RD-VBA tests. It targets .NET 11 and depends on RDCore.SDK. Its symbols are on NuGet's symbol server.
Full changes: commits up to v0.1.0-alpha.