现在我正在制作用于清除代码覆盖率的 Apex 测试用例。
使用普通代码如下,
测试数据工厂
@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/