??????dotnet?????У???????????NUnit??RhinoMocks????д????????
????NUnit ???
????NUnit??.net?????????????????????????????????????????????????д????????
????http://www.nunit.org?????°汾?2.6.3.
???????????????????????????汾????????
????http://www.nunit.org/index.php?p=documentation
????Rhino Mocks???
????Rhino Mocks????????????????????????????????????????????????????????????????????
????????????http://hibernatingrhinos.com/downloads/rhino-mocks/latest
??????α?д????????
????????????????????????{?????????}.UnitTest?? ?????NUnit??RhinoMocks???á????????????Application ????е?Outputtype?????Class Library
?????????dll ???nunit.framework.dll??Rhino.Mocks.dll
???????????????????{????????}Test????????????????????????????????????
????????????????????????NUnit.Framework??Rhino.Mocks
????using NUnit.Framework;
????using Rhino.Mocks;
????????????summary????У??г??????б??????????????[TestFixture]?????
????[TestFixture]
????class SchoonerStorageTest
????{
????}
???????????б??????????????????????[Test]???????????????????Test_{TestedMethod}_{?????}_{?????}??????????????????????
????[Test]
????public void Test_{TestedMethod}_{?????}_{?????}()
????{
????????????????:
????//???????????
????//??б????????
????//??????????
????}
????????????е?NUnit
??????????????й???
[TestFixture]
public class TestFixtureSetUpAndTearDownTest
{
[TestFixtureSetUp]
public void RunBeforeAllTests()
{
Console.WriteLine("TestFixtureSetUp");
}
[TestFixtureTearDown]
public void RunAfterAllTests()
{
Console.WriteLine("TestFixtureTearDown");
}
[SetUp]
public void RunBeforeEachTest()
{
Console.WriteLine("SetUp");
}
[TearDown]
public void RunAfterEachTest()
{
Console.WriteLine("TearDown");
}
[Test]
public void Test1()
{
Console.WriteLine("Test1");
}
}
????TestFixtureSetUp???????????????????????Σ?
????SetUp?????????????????????????Σ?
????Test????в?????????
????TearDown??????????????????????????Σ?
????TestFixtureTeardDown???????????????????????Σ?
????????????Assertions)
????????????????
????????????classic model??
???????????Assert.AreEqual?? Assert.AreNotEqual...)
???????????????Assert.AreSame?? Assert.AreNotSame...)
???????????Assert.Greater?? Assert.Less ...)
????????????Assert.IsInstanceOfType?? Assert.IsAssignableFrom...??
???????????? ??Assert.True?? Assert.False?? Assert.IsNan?? Assert.IsNull?? Assert.IsEmpty??
????Assert????????????(??Щ???????????????????п????
????Assert.Pass??????????????
????The Assert.Pass method allows you to immediately end the test?? recording it as successful. Since it causes an exception to be thrown?? it is more efficient to simply allow the test to return. However?? Assert.Pass allows you to record a message in the test result and may also make the test easier to read in some situations. Additionally?? like the other methods on this page?? it can be invoked from a nested method call with the result of immediately terminating test execution.
????Assert.Fail??????????????
????The Assert.Fail method provides you with the ability to generate a failure based on tests that are not encapsulated by the other methods. It is also useful in developing your own project-specific assertions.
????Assert.Ignore?????????????
????The Assert.Ignore method provides you with the ability to dynamically cause a test or suite to be ignored at runtime. It may be called in a test?? setup or fixture setup method. We recommend that you use this only in isolated cases. The category facility is provided for more extensive inclusion or exclusion of tests or you may elect to simply divide tests run on different occasions into different assemblies.
????Assert.Inconclusive????????????????в?????????????????????????????????????ó?????
????The Assert.Inconclusive method indicates that the test could not be   completed with the data available. It should be used in situations where   another run with different data might run to completion?? with either a   success or failure outcome.
????DirectoryAssert??
????FileAssert??
????CollectionAssert??
????StringAssert??
?????????????????constraint-based model)
??????????????????????????????
????Assert.That(..)
???????????(Attributes)
??????????????
????[Test(Description = "If the Id or Name attribute is not found in xpath 'StorageManagement/WritePolicy/CategoryConfig/CategoryList/Category'?? an exception will be thrown.")]
????[ExpectedException(ExpectedException = typeof(ConfigException)?? MatchType = MessageMatch.Contains?? ExpectedMessage = "Id?? Name attributes are required")]
????public void Test_LoadConfig_RequiredInfoNotFound_CategoryInWritePolicyCategoryList()
????{
????string confileFile = GetTestFile("CategoryStorageConfig_RequiredInfoNotFound_CategoryInWritePolicyCategoryList.xml");
????categoryStorageConfig.LoadConfig(confileFile);
????Assert.Fail("Failure");
????}