testing - Salesforce/Apex,为什么 TestDataFactory 类包含在代码覆盖率中?

标签 testing salesforce apex

现在我正在制作用于清除代码覆盖率的 Apex 测试用例。

使用普通代码如下,

https://developer.salesforce.com/docs/atlas.en-us.198.0.apexcode.meta/apexcode/apex_testing_utility_classes.htm

测试数据工厂

@isTest
public class TestDataFactory{
    public List<Account> createAccounts(){
        // data create...
        return accounts;
    }
    // data create methods...
    .
    .
    .
}

我的测试类

@isTest
private class MyTestClass {
    static testmethod void test1() {
        TestDataFactory.createAccounts();
        // Run some tests
    }
    // other testmethods
    .
    .
    .
}

我的TestDataFactory类的行数是100行,MyTestClass 100行是测试用例逻辑已经完成的代码覆盖。

因此,100 行/200 行。 代码覆盖率为 50%。

因为TestDataFactory类的代码覆盖率是0%。

我该如何解决?

我很抱歉英语不好。感谢您阅读。

最佳答案

它按预期工作。很快,

Including code other than test methods in an @isTest annotated class will cause these lines to be counted in the overall code coverage numbers

请检查Why is a Test class evaluated as part of the Organization’s Code Coverage?

我建议您从 TestDataFactory 类中删除 @isTest,以免混淆任何人。当您在测试中使用所有方法时,它将被 100% 覆盖。

关于testing - Salesforce/Apex,为什么 TestDataFactory 类包含在代码覆盖率中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34660111/

相关文章:

android - 我的 Android 应用程序应该使用哪个云数据库后端?

java - Apex 数据加载器 - 错误 java.lang.UnsatisfiedLinkError : Cannot load 32-bit SW T libraries on 64-bit JVM

salesforce - 什么是销售队伍中的动态巅峰?

javascript - 如何进一步减少加载时间(Visualforce、Apex、Angular)

salesforce - 相关列表仅在 salesforce 中

javascript - stub 和代理

java - 无法在 Spring Boot Test 1.5 中设置运行时本地服务器端口

excel - 在 VF 页面中导出 Excel - 使用动态图像 URL 时图像未显示

javascript - 如何使用带有 JavaScript 的小 cucumber 和 cucumber 为每个步骤创建屏幕截图?

c# - VS2010 Test Professional/Team Server 的替代品?