Skip to content

Releases

RDCore.UnitTesting v0.1.0-alpha

Pre-release

Choose a tag to compare

@RubberduckAdmin RubberduckAdmin released this 29 Nov 06:20
de78291

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: '@TestModule on a standard module makes it a test module, and '@TestMethod on a public Sub of it makes the Sub a test. The platform completes and describes the test annotations.
  • The RDTest library and its Assert module: IsTrue, IsFalse, IsNothing, IsNotNothing, AreEqual, AreNotEqual, AreSame, AreNotSame, SequenceEquals, NotSequenceEquals, Succeed, Inconclusive and Fail, each with an optional message. A project uses it with a reference to RDTest. AreEqual compares as the = operator does, with the calling module's Option Compare, and AreSame as Is does. A failure says what was expected and what the run had, in English or French.
  • Setup and cleanup: '@ModuleInitialize runs once before a module's tests, '@TestInitialize and '@TestCleanup around each test (the cleanup whatever the outcome), and '@ModuleCleanup once after them. They run from outside their module, so they are Public (RDT00009). A '@ModuleInitialize or '@TestInitialize that is not Public fails the module's tests, saying why. A '@TestCleanup that is not Public fails each test it follows that had passed, and a '@ModuleCleanup that is not Public does not run.
  • '@ExpectedError(n): a test passes when it raises error n, and fails when it raises another error or none.
  • '@TestCase rows: 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 line Passed: 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 folder rdc runs 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 End statement 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 Assert is 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.ps1 publishes RDCore.UnitTesting into a platform's Extensions folder, 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 the RDT diagnostic 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.