- autp3_demo.zip
- Lib
- UnitTest.sln
- UnitTest.suo
- UnitTest
- UTCore
- UTExample
- UTWinForm
- App.ico
- AssemblyInfo.cs
- bin
- Debug
- config.xml
- Fail.ico
- Ignore.ico
- ka.ico
- Lib.dll
- Lib.pdb
- NotRun.ico
- Pass.ico
- UnitTest.dll
- UnitTest.pdb
- Untested.ico
- UTCore.dll
- UTCore.pdb
- UTExample.dll
- UTExample.pdb
- UTWinForm.exe
- UTWinForm.pdb
- obj
- Debug
- temp
- TempPE
- UTWinForm.exe
- UTWinForm.Form1.resources
- UTWinForm.pdb
- UTWinForm.projdata
- UTWinForm.cs
- UTWinForm.csproj
- UTWinForm.csproj.user
- UTWinForm.resx
|
using System;
using System.Collections;
using System.Diagnostics;
using KALib;
namespace UTCore
{
public delegate void TestNotificationDelegate(UTCore.TestAttribute ta);
public class TestRunner
{
public enum ProcDir
{
RunProcessForward,
RunProcessReverse,
}
private AssemblyCollection assemblyCollection;
private ArrayList testFixtureList;
public event TestNotificationDelegate testNotificationEvent;
private int numTests;
private static ProcDir processDirection;
public AssemblyCollection AssemblyCollection
{
get {return assemblyCollection;}
}
public ArrayList TestFixtures
{
get {return testFixtureList;}
}
public int NumTests
{
get {return numTests;}
}
public static ProcDir ProcessDirection
{
get {return processDirection;}
set {processDirection=value;}
}
public TestRunner()
{
assemblyCollection=new AssemblyCollection();
testFixtureList=new ArrayList();
}
public void LoadAssembly(string file)
{
AssemblyItem ai=new AssemblyItem();
ai.Load(file);
ai.LoadNamespaces();
ai.LoadClasses();
ai.LoadMethods();
assemblyCollection.Add(file, ai);
}
public void ParseAssemblies()
{
numTests=0;
foreach (AssemblyItem ai in assemblyCollection.Values)
{
foreach (NamespaceItem ni in ai.NamespaceCollection.Values)
{
foreach (ClassItem ci in ni.ClassCollection.Values)
{
TestFixture tf=new TestFixture();
foreach (object attr in ci.Attributes)
{
// verify that attribute class is "UnitTest"
string attrStr=attr.ToString();
attrStr=StringHelpers.RightOfRightmostOf(attrStr, '.');
Trace.WriteLine("Class: "+ci.ToString()+", Attribute: "+attrStr);
try
{
Type t=Type.GetType("UTCore."+attrStr);
TestUnitAttribute tua=Activator.CreateInstance(t) as TestUnitAttribute;
tua.Initialize(ci, null, attr);
tua.SelfRegister(tf);
}
catch(Exception e)
{
Trace.WriteLine("Exception adding attribute: "+e.Message);
Trace.WriteLine("Attribute "+attrStr+" is unknown");
}
}
if (tf.HasTestFixture)
{
foreach(MethodItem mi in ci.MethodCollection.Values)
{
foreach (object attr in mi.Attributes)
{
// verify that attribute class is "UnitTest"
string attrStr=attr.ToString();
attrStr=StringHelpers.RightOfRightmostOf(attrStr, '.');
Trace.WriteLine("Method: "+mi.ToString()+", Attribute: "+attrStr);
try
{
Type t=Type.GetType("UTCore."+attrStr);
TestUnitAttribute tua=Activator.CreateInstance(t) as TestUnitAttribute;
tua.Initialize(ci, mi, attr);
tua.SelfRegister(tf);
}
catch(Exception e)
{
Trace.WriteLine("Attribute "+attrStr+"is unknown: "+e.Message);
}
}
}
testFixtureList.Add(tf);
numTests+=tf.NumTests;
}
}
}
}
}
public void RunTests()
{
foreach(TestFixture tf in testFixtureList)
{
tf.RunTests(testNotificationEvent);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here