Tag: testcase

如何在NUnit 2.5中使用TestCase?

我有一个Currency类,我使用NHibernate将其保存到我的数据库中。 Currency类看起来像这样: public class Currency : Entity { public virtual string Code { get; set; } public virtual string Name { get; set; } public virtual string Symbol { get; set; } } 我使用[TestCase]编写了一个unit testing,如下所示: [TestCase(6,Result = new Currency ({ Code=”GBP”, Name=”British Pound”, Symbol=”£”}))] public Currency CanGetCurrencyById(int id) { ICurrencyRepo currencies = new RepoFactory().CreateCurrencyRepo(_session); Currency […]

NUnit在包含数组时无法识别TestCase

这是非常简单但令人烦恼的行为,我遇到了NUnit: 我有一些像这样的测试: [Test] [TestCase( 1, 2, “hello” )] [TestCase( 3, 5, “goodbye” )] public void MyClass_MyMethod( int a, int b, string c ) { Assert.IsTrue( a < b ); } 这很好用,在ReSharper NUnit窗格中,我可以看到每个TestCase在结果中获得自己的响应。 我有第二个看起来像这样的TestCase: [Test] [TestCase( 1, 2, new long[] { 100, 200 })] [TestCase( 5, 3, new long[] { 300, 500 })] public void MyClass_MyOtherMethod( […]

如何将新的List {1}放入NUNIT TestCase中?

我有方法: public static int Add(List numbers) { if (numbers == null || numbers.Count == 0) return 0; if (numbers.Count == 1) return numbers[0]; throw new NotImplementedException(); } 这是我对它的测试,但它不喜欢TestCase中的new List {1} : [TestCase(new List{1}, 1)] public void Add_WithOneNumber_ReturnsNumber(List numbers) { var result = CalculatorLibrary.CalculatorFunctions.Add(numbers); Assert.AreEqual(1, result); } 它给了我错误: An attribute argument must be a constant expression, […]