Test suite users may want to refer to the CodeDom Test Suite Readme document also located in this collection. This document is for those who want to extend the test suite with their own test cases.
The CodeDom test suite allows you to write and build test cases independent
of the ones provided with the test suite. These test cases all must derive
from the class CodeDomTest
(or its subtypes) located in
CodeDomTest.dll
. This class provides the test suite a single
interface with which to call and handle your test. There is a subtype
of CodeDomTest
, namely CodeDomTestTree
, that takes
care of more details for you. The differences between the two are described
below.
Note in order to take advantage of the passed in options: saveassemblies and savesources, you must override CodeDomTestTree.
The CodeDomTest
class requires you to override the following
properties and methods:
TestTypes
TestType
Should return one of the following values from the TestTypes
enum: Subset
, Everett
,
Whidbey
. Refer to the readme
for more information about these classifications.
string
Name
Returns the name of the test. If you compile many tests into a single assembly, the names should be unique otherwise the test suite will detect multiple names and abort any test runs.
string
Description
Returns a short description of the test. It is recommended that this be no longer than one or two lines on the console window.
bool
Run (CodeDomProvider
provider)
This method does all the testing on the given provider. The
CodeDomTestTree
implements this for you. Returning
true
from this method signifies a test case pass.
false
signifies a fail.
CodeDomTestTree
Many CodeDom provider tests do the same kind of verification test. That is they:
The CodeDomTestTree
automates these three steps
allowing you to focus on writing the test tree and verification. It also provides
sub-scenario verification.
With these steps in mind, if you override CodeDomTestTree
, the
following methods should be implemented (note that you must still implement
the three TestType, Name and Description properties):
bool
ShouldCompile
Signifies whether or not the generated CodeDom tree (from BuildTree) should compile.
bool
ShouldVerify
Signifies whether or not the compiled code from your CodeDom tree should be verified.
bool
ShouldSearch
Signifies whether or not the generated code from your CodeDom tree should be searched using
the provided Search
function.
void
BuildTree (CodeDomProvider
provider,
CodeCompileUnit
cu)
Takes the given provider and generates a tree in the given CodeCompileUnit. This is where the bulk of your test case should reside. You may use AddScenario()
void
VerifyAssembly (CodeDomProvider
provider,
Assembly
builtAssembly)
Runs verification of the compiled source code emitted by the provider. The source code is generated from the tree you built in BuildTree(). You should use VerifyScenario() to verify any scenarios defined in BuildTree(). You may also add new scenarios as long as they are also verified by the end of VerifyAssembly()'s execution. Refer to the accompanying documentation for more information on how to write a test case.
void
Search (CodeDomProvider
provider
string
source)
Searches the given code output as you define. The given string will be the source code emitted by the given provider that was generated from the tree defined in BuildTree(). You should use VerifyScenario() as in VerifyAssembly() to match any successful scenarios.