- xmlcompiler.zip
- aut
- CVS
- MuteLib
- UnitTest
- UTWinForm
- Clifton.Tools.Compiler
- Clifton.Tools.Data
- Clifton.Tools.Strings
- Clifton.Tools.Xml
|
/*
(c) 2005, Marc Clifton
All Rights Reserved
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
Neither the name of the Marc Clifton, "Advanced Unit Test", "AUT", nor the names
of its contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
namespace Vts.UTCore
{
public class TestFixture
{
#region Events
private event TestNotificationDelegate testNotificationEvent;
private event FixtureNotificationDelegate fixtureNotificationEvent;
private event TestIterationDelegate testIterationEvent;
internal void NotifyTestListeners(UTCore.TestAttribute ta, TestEvent testEvent)
{
if(testNotificationEvent != null)
testNotificationEvent(ta, testEvent);
}
internal void NotifyIterationListeners(UTCore.TestAttribute ta)
{
if(testIterationEvent != null)
testIterationEvent(ta);
}
internal void NotifyTestListeners(UTCore.TestUnitAttribute tua, TestEvent testEvent)
{
if (fixtureNotificationEvent != null)
{
fixtureNotificationEvent(tua, testEvent);
}
}
#endregion
#region Fields
private TestUnitAttribute tfa=null; // TestFixtureAttribute. one per TF, indicating test fixture
private TestUnitAttribute fsua=null; // TestFixtureSetUpAttribute. one per TF, run once for all tests in the fixture
private TestUnitAttribute ftda=null; // TestFixtureTearDownAttribute. one per TF, run once for all tests in the fixture
private TestUnitAttribute sua=null; // SetUpAttribute. one per TF, run each time for all tests
private TestUnitAttribute tda=null; // TearDownAttribute. one per TF, run each time for all tests
private CodePathRangeAttribute cpra=null; // CodePathRangeAttribute
private CodePathsAttribute cpa=null; // CodePathAttribute
private ArrayList testList=null; // many per TF, run once per fixture
private Hashtable testsByName=null;
private Hashtable fixtureCodePathTracker=null;
private Hashtable methodCodePathTracker=null;
private bool isProcessTest=false;
private bool isIgnored=false;
private string ignoreReason="";
private object instance;
private int startCodePath;
private int stopCodePath;
private int[] codePaths;
#endregion
#region Properties
public Hashtable FixtureCodePathTracker
{
get {return fixtureCodePathTracker;}
}
public Hashtable MethodCodePathTracker
{
get {return methodCodePathTracker;}
}
public int StartCodePath
{
get {return startCodePath;}
set {startCodePath=value;}
}
public int StopCodePath
{
get {return stopCodePath;}
set {stopCodePath=value;}
}
public int[] CodePathList
{
get {return codePaths;}
set {codePaths=value;}
}
public bool HasTestFixture
{
get {return tfa.GetType() != typeof(NullTestUnitAttribute);}
}
public bool HasCodePathRange
{
get {return cpra != null;}
}
public bool HasCodePathList
{
get {return cpa != null;}
}
internal Assembly Assembly
{
get {return tfa.TestClass.Assembly;}
}
public string AssemblyName
{
get { return tfa.TestClass.AssemblyName; }
}
public string Namespace
{
get {return tfa.TestClass.Namespace;}
}
public int NumTests
{
get {return testList.Count;}
}
public string IgnoreReason
{
get {return ignoreReason;}
set {ignoreReason=value;}
}
public bool IgnoreFixture
{
get {return isIgnored;}
set {isIgnored=value;}
}
public bool IsProcessTest
{
get {return isProcessTest;}
set {isProcessTest=value;}
}
public TestUnitAttribute TFA
{
get {return tfa;}
}
public TestUnitAttribute TestSetUp
{
get {return sua;}
}
public TestUnitAttribute TestTearDown
{
get {return tda;}
}
public CodePathRangeAttribute CodePathRange
{
get {return cpra;}
}
public CodePathsAttribute CodePaths
{
get {return cpa;}
}
public ArrayList TestList
{
get {return testList;}
}
public TestAttribute this[string index]
{
get {return testsByName[index] as TestAttribute;}
}
#endregion
#region c'tors
public TestFixture()
{
testList=new ArrayList();
testsByName=new Hashtable();
tfa=new NullTestUnitAttribute();
fsua=new NullTestUnitAttribute();
ftda=new NullTestUnitAttribute();
sua=new NullTestUnitAttribute();
tda=new NullTestUnitAttribute();
cpra=null;
cpa=null;
}
#endregion
#region Methods
public void AddTestFixtureAttribute(TestFixtureAttribute tfa)
{
this.tfa=tfa;
}
public void AddFixtureSetUpAttribute(TestFixtureSetUpAttribute fsua)
{
this.fsua=fsua;
}
public void AddFixtureTearDownAttribute(TestFixtureTearDownAttribute ftda)
{
this.ftda=ftda;
}
public void AddSetUpAttribute(SetUpAttribute sua)
{
this.sua=sua;
}
public void AddTearDownAttribute(TearDownAttribute tda)
{
this.tda=tda;
}
public void AddTestAttribute(TestAttribute ta)
{
testList.Add(ta);
testsByName.Add(ta.TestMethod.ToString(), ta);
}
public void AddCodePathRangeAttribute(CodePathRangeAttribute cpra)
{
this.cpra=cpra;
}
public void AddCodePathsAttribute(CodePathsAttribute cpa)
{
this.cpa=cpa;
}
public void RunTests(TestNotificationDelegate testNotificationEvent, FixtureNotificationDelegate fixtureNotificationEvent, TestIterationDelegate testIterationEvent, Hashtable fixtureCodePathTracker, Hashtable methodCodePathTracker)
{
this.testNotificationEvent=testNotificationEvent;
this.fixtureNotificationEvent=fixtureNotificationEvent;
this.testIterationEvent=testIterationEvent;
this.fixtureCodePathTracker=fixtureCodePathTracker;
this.methodCodePathTracker=methodCodePathTracker;
TestFixtureRunner tfr=CreateTestFixtureRunner();
tfr.RunTests();
}
public object SetUpClass()
{
instance=tfa.CreateClass();
if (!isIgnored)
{
fsua.Invoke(instance);
}
return instance;
}
public void TearDownClass()
{
if (!isIgnored)
{
ftda.Invoke(instance);
}
}
// test fixture runner factory
public TestFixtureRunner CreateTestFixtureRunner()
{
if (isProcessTest)
{
return new TestFixtureRunProcess(this);
}
return new TestFixtureRunIndividual(this);
}
#endregion
}
}
|
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.