This project is read-only.
Anise provides a dependency injected unit test framework to make it easy to test your dependency injected classes. To make a unit test, simply create a subclass of AniseUnitTest, and define your tests as methods which begin with the word “Test”. If you would like to run setup and tear down code, you may override the SetUp and TearDown methods. These will be called immediately before/after each of your tests. Any objects to be tested can be injected into the test object using a normal C# property. Here’s an example from Anise’s own unit tests:

     1: public class AniseScriptTest : AniseUnitTest
     2: {
     3:     public override void Setup()
     4:     {
     5:         // Perform setup functions
     6:     }
     8:     public override void TearDown()
     9:     {
    10:         // Perform tear-down functions
    11:     }
    13:     public void TestLoadTextWithSingleLine()
    14:     {
    15:         script.LoadText("alpha");
    17:         // Use the various Assert… methods from the parent class
    18:         AssertEqual(1, script.Lines.Count);
    19:         AssertEqual("alpha", script.Lines[0].Text);
    20:         AssertEqual("inline0", script.Lines[0].Position.SourceFile);
    21:         AssertEqual(1, script.Lines[0].Position.LineNumber);
    22:         AssertEqual(1, script.Lines[0].Position.Column);
    23:     }
    25:     internal AniseScript script { get; set; }
    26: }

To configure the test, you could define it (along with its fixtures) in an Anise script:

     1: script-test = {
     2:     _class = Microsoft.LiveLabs.Anise.UnitTest.AniseScriptTest;
     3:     script = {
     4:         _class = Microsoft.LiveLabs.Anise.Core.AniseScript;
     5:     };
     6: };

Finally, assuming you saved your script in a file called MyTests.adi, you could run your tests using the following command on the command line:

    > Anise.exe /file MyTests.adi /test

This would make Anise look through all the definitions in your file looking for anything which is a subclass of AniseUnitTest . For each unit test class it identifies, it will then examine the class for any methods which begin with the word “Test”. For each test method it finds, it will then create an instance of the test object (injecting any dependencies), call the SetUp method, then the test method, then the TearDown method. If all the tests pass, then that fact will be reported on the console. If any fail, that fact will be reported along with details on the failing test(s). In order to re-run a specific subset of tests, simply provide the name of the object whose tests you would like to run (e.g. /test script-test).

Last edited Jun 28, 2010 at 1:01 AM by aminer, version 3


No comments yet.