首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >dotCover不覆盖测试

dotCover不覆盖测试
EN

Stack Overflow用户
提问于 2018-04-12 17:00:31
回答 1查看 59关注 0票数 0

我已经创建了一个简单的类BankAccount

代码语言:javascript
复制
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);
        }
    }
}

对于这个类,我实现了一些测试:

代码语言:javascript
复制
[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()。这个是可能的吗?

EN

回答 1

Stack Overflow用户

发布于 2018-04-16 20:38:28

看起来只有WithdrawTest执行了覆盖率分析。您是否可以尝试执行“覆盖当前会话”操作(参见“运行当前会话”按钮下的下拉菜单)?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49792298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档