Table of Contents

RDT00009: Test is not Public

Severity: Warning  ·  Family: RDT (RDCore.UnitTesting)  ·  Raised by: TestShapeAnalyzer

A Private or Friend procedure is annotated as a test, or as the setup or cleanup of a module or of its tests.

A test run calls a test, and a module's '@ModuleInitialize, '@ModuleCleanup, '@TestInitialize and '@TestCleanup, as entry points, and runs only a Public one. A Private procedure is accessible only within its module, and a Friend procedure cannot be declared in a standard module (MS-VBAL §5.3.1.1 Procedure Scope). A test that is not Public fails without running, and so does every test of a module whose '@ModuleInitialize or '@TestInitialize is not Public. A '@TestCleanup that is not Public fails each test it follows that had passed, and a '@ModuleCleanup that is not Public does not run. A procedure declared with no access keyword is Public.

It is reported at the procedure's name.

How it is raised

Situation Example Resolution
A test that is Private. '@TestMethod above Private Sub AddsTwoNumbers(). Make it Public, or remove the access keyword.
A setup procedure that is Private. '@TestInitialize above Private Sub TestInitialize(). Make it Public. A helper the tests call needs no annotation and can stay Private.

Quick fix

The quick fix, Make 'AddsTwoNumbers' Public, writes Public in place of Private or Friend. The procedure's calls in its module do not change.

See also