我已经创建了一个简单的类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%测试覆盖率,但我不知道为什么。有一个Test,它确实测试了该方法的一个用例。

我做错了什么?我们的目标是表明,一次测试将覆盖50%的BankAccount.WithdrawOrDeposite()。这个是可能的吗?
发布于 2018-04-16 20:38:28
看起来只有WithdrawTest执行了覆盖率分析。您是否可以尝试执行“覆盖当前会话”操作(参见“运行当前会话”按钮下的下拉菜单)?
https://stackoverflow.com/questions/49792298
复制相似问题