我正在编写一个数据密集型应用程序.我有以下测试.他们工作,但他们是多余的.
[Test]
public void DoSanityCheck_WithCountEqualsZeroAndHouseGrossIsGreater_InMerchantAggregateTotals_SetsWarning()
{
report.Merchants[5461324658456716].AggregateTotals.ItemCount = 0;
report.Merchants[5461324658456716].AggregateTotals._volume = 0;
report.Merchants[5461324658456716].AggregateTotals._houseGross = 1;
report.DoSanityCheck();
Assert.IsTrue(report.FishyFlag);
Assert.That(report.DataWarnings.Where(x=> x is Reports.WarningObjects.ImbalancedVariables && x.mid == 5461324658456716 && x.lineitem == "AggregateTotals").Count() > 0);
}
[Test]
public void DoSanityCheck_WithCountEqualsZeroAndHouseGrossIsGreater_InAggregateTotals_SetsWarning()
{
report.AggregateTotals.ItemCount = 0;
report.AggregateTotals._volume = 0;
report.AggregateTotals._houseGross = 1;
report.DoSanityCheck();
Assert.IsTrue(report.FishyFlag);
Assert.That(report.DataWarnings.Where(x=> x is Reports.WarningObjects.ImbalancedVariables && x.mid == null && x.lineitem == "AggregateTotals").Count() > 0);
}
[Test]
public void DoSanityCheck_WithCountEqualsZeroAndHouseGrossIsGreater_InAggregateTotalsLineItem_SetsWarning()
{
report.AggregateTotals.LineItem["WirelessPerItem"].ItemCount = 0;
report.AggregateTotals.LineItem["WirelessPerItem"]._volume = 0;
report.AggregateTotals.LineItem["WirelessPerItem"]._houseGross = 1;
report.DoSanityCheck();
Assert.IsTrue(report.FishyFlag);
Assert.That(report.DataWarnings.Where(x=> …Run Code Online (Sandbox Code Playgroud) 我正在使用NUnit 2.5.3 TestCaseSource属性并创建工厂来生成我的测试.像这样的东西:
[Test, TestCaseSource(typeof(TestCaseFactories), "VariableString")]
public void Does_Pass_Standard_Description_Tests(string text)
{
Item obj = new Item();
obj.Description = text;
}
Run Code Online (Sandbox Code Playgroud)
我的来源是这样的:
public static IEnumerable<TestCaseData> VariableString
{
get
{
yield return new TestCaseData(string.Empty).Throws(typeof(PreconditionException))
.SetName("Does_Reject_Empty_Text");
yield return new TestCaseData(null).Throws(typeof(PreconditionException))
.SetName("Does_Reject_Null_Text");
yield return new TestCaseData(" ").Throws(typeof(PreconditionException))
.SetName("Does_Reject_Whitespace_Text");
}
}
Run Code Online (Sandbox Code Playgroud)
我需要做的是向变量字符串添加最大长度检查,但是这个最大长度是在被测试类中的合同中定义的.在我们的例子中它是一个简单的公共结构
public struct ItemLengths
{
public const int Description = 255;
}
Run Code Online (Sandbox Code Playgroud)
我找不到任何方法将值传递给测试用例生成器.我尝试过静态共享值,但这些值并没有被提取.我不想将文件保存到文件中,因为每次代码更改时我都需要重新生成此文件.
我想在我的测试用例中添加以下行:
yield return new TestCaseData(new string('A', MAX_LENGTH_HERE + 1))
.Throws(typeof(PreconditionException));
Run Code Online (Sandbox Code Playgroud)
在概念上相当简单,但我发现无法做到的事情.有什么建议?