-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApexUnitTestClassShouldHaveAsserts.xml
132 lines (121 loc) · 5.51 KB
/
ApexUnitTestClassShouldHaveAsserts.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?xml version="1.0" encoding="UTF-8"?>
<test-data
xmlns="http://pmd.sourceforge.net/rule-tests"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-code>
<description>Problematic apex unit test - no assert calls</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
@isTest
public class Foo {
public static testMethod void testSomething() {
Account a = null;
// This is better than having a NullPointerException
// System.assertNotEquals(a, null, 'account not found');
a.toString();
}
}
]]></code>
</test-code>
<test-code>
<description>#1543 [apex] ApexUnitTestClassShouldHaveAsserts assumes APEX is case sensitive</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
@isTest
public class Foo {
public static testMethod void testSomething() {
Account a = null;
SYSTEM.AssertNotEquals(a, null, 'account not found');
}
}
]]></code>
</test-code>
<test-code>
<description>#1521 [apex] ApexUnitTestClassShouldHaveAsserts: Parsing error on APEX class: expected one element but was: <BlockStatement, BlockStatement></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
@isTest
private class C2_Assignment_Report_Job_Test {
public static testMethod void testCreateAssignmentsForDifferentRoles() {
User u = C2_Test_Utils.getWFUser('testWfc', true);
System.runAs(u) {
C2_Assignment_Report_Data_Aggregate_Job job = new C2_Assignment_Report_Data_Aggregate_Job();
String query = job.start(null).getQuery();
C2_Receiver_Unit__c ru = new C2_Receiver_Unit__c(Name='RU1');
insert ru;
List<C2_Case__c> cases = new List<C2_Case__c>();
cases.add(new C2_Case__c(Name='TT0000000', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
cases.add(new C2_Case__c(Name='TT0000001', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
cases.add(new C2_Case__c(Name='TT0000002', Queue__c = 'PA-CSA', Status__c=C2_Case_Util.STATUS_NEW, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
cases.add(new C2_Case__c(Name='TT0000011', Queue__c = 'DSA', Status__c=C2_Case_Util.STATUS_PACSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
cases.add(new C2_Case__c(Name='TT0000012', Queue__c = 'DSA', Status__c=C2_Case_Util.STATUS_PACSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
cases.add(new C2_Case__c(Name='TT0000021', Queue__c = 'QR-CSA', Status__c=C2_Case_Util.STATUS_DSA_COMPLETE, PA_CSA__c=u.Id, DSA__c=u.Id, QR_CSA__c=u.Id, Receiver_Unit__c=ru.Id));
insert cases;
List<C2_Case__c> scope = Database.query(query);
Test.startTest();
job.execute(null, scope);
Test.stopTest();
List<C2_Case_Assign_Report_Data__c> caseEventEntries =
[select Num_Cases_Assign__c, Num_Cases_Not_Completed__c, Num_Cases_Reassigned__c, Num_Cases_Completed__c, User__c, Role__c
from C2_Case_Assign_Report_Data__c];
System.assertEquals(3, caseEventEntries.size());
Map<String, Integer> userIdWithRole2ReportData = getCaseEventEntriesMap(caseEventEntries);
System.assertEquals(3, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'PA-CSA')));
System.assertEquals(2, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'DSA')));
System.assertEquals(1, userIdWithRole2ReportData.get(createUserRoleKey(u.Id, 'QR-CSA')));
}
}
}
]]></code>
</test-code>
<test-code>
<description>#1089 [apex] ApexUnitTestClassShouldHaveAsserts: Verify use of additionalAssertMethodPattern, positive test</description>
<rule-property name="additionalAssertMethodPattern">(Assert\.\w+|verify\w+)</rule-property>
<expected-problems>0</expected-problems>
<code><![CDATA[
@isTest
public class Foo {
public static testMethod void testAssertIsTrue() {
Assert.isTrue(someCondition);
}
public static testMethod void testLocalVerify() {
verifyState();
}
private static void verifyState() {
}
}
]]></code>
</test-code>
<test-code>
<description>#1089 [apex] ApexUnitTestClassShouldHaveAsserts: Verify use of additionalAssertMethodPattern, negative test</description>
<expected-problems>2</expected-problems>
<expected-linenumbers>3,7</expected-linenumbers>
<code><![CDATA[
@isTest
public class Foo {
public static testMethod void testAssertEqual() {
Assert.assertEquals(null, someCondition);
}
public static testMethod void testLocalVerify() {
verifyState();
}
private static void verifyState() {
}
}
]]></code>
</test-code>
<test-code>
<description>#4096 [apex] api 56.0 ApexAssertionsShouldIncludeMessage and new apex class : Assert</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
@isTest
public class Foo {
public static testMethod void testSomething() {
Account a = null;
Assert.areEqual(a, null, 'account not found');
}
}
]]></code>
</test-code>
</test-data>