我创建了一个简单的类BankAccount
public class BankAccount {
public decimal Balance { get; set; }
public void Withdraw(decimal amount) {
this.Balance -= amount;
}
public void Deposit(decimal amount) {
this.Balance += amount;
}
public void WithdrawOrDeposit(decimal amount) {
if (amount < 0) {
this.Withdraw(Math.Abs(amount));
} else {
this.Deposit(amount);
}
}
}
对于本课程,我实施了一些测试:
[TestFixture]
public class BankAccountTests {
private BankAccount account;
[SetUp]
public void SetUp() {
this.account = new BankAccount {Balance = 100};
}
[Test]
public void WithdrawTest() {
this.account.Withdraw(50);
Assert.That(this.account.Balance, Is.EqualTo(50));
}
[Test]
public void WithdrawOrDepositTest() {
this.account.WithdrawOrDeposit(50);
Assert.That(this.account.Balance, Is.EqualTo(150));
}
}
当我现在执行dotCover时,它显示方法BankAccount.WithdrawOrDeposite()
的0%Testcoverage,但我不知道为什么。有一个测试,它测试该方法的一个案例。
我做错了什么?目标是表明,50%的BankAccount.WithdrawOrDeposite()
将被测试覆盖。这可能吗?
答案 0 :(得分:0)
看起来只有WithdrawTest执行了覆盖率分析。您能否尝试执行&#34;报道当前会议&#34;操作(请参阅&#34;运行当前会话&#34;按钮下的下拉菜单?)