我正试图让NUnit第一次工作。
我试过了:
这是输出:
using System;
namespace bankAccount
{
public class Account
{
private int balance;
public Account(int initialBalance)
{
balance = initialBalance;
}
public void credit(int amount)
{
balance += amount;
}
public void debit(int amount)
{
balance -= amount;
}
public int getBalance()
{
return balance;
}
}
}
要测试的课程:
using System;
using System;
using System.Collections.Generic;
using System.Text;
using bankAccount;
using NUnit.Framework;
namespace accountTest
{
[TestFixture]
public class AccountTest
{
//private Account account;
[Test]
public void initialBalance()
{
Account account = new Account(100);
Assert.AreEqual(100, account.getBalance());
}
[Test]
public void credit()
{
Account account = new Account(100);
account.credit(20);
Assert.AreEqual(130, account.getBalance());
}
[Test]
public void debitOk()
{
Account account = new Account(100);
account.debit(20);
Assert.AreEqual(80, account.getBalance());
}
}
}
然后是测试类:
{{1}}