@@ -9,219 +9,154 @@ import org.junit.Test
9
9
import static com.vanniktech.android.junit.jacoco.ProjectHelper.ProjectType.*
10
10
11
11
public class GenerationTest {
12
-
13
12
@Test
14
13
public void addJacocoAndroidAppWithFlavors () {
15
-
16
- // Given
17
14
def androidAppProject = ProjectHelper . prepare(ANDROID_APPLICATION ). withRedBlueFlavors(). get()
18
15
19
- // When
20
16
Generation . addJacoco(androidAppProject, new JunitJacocoExtension ())
21
17
22
- // Then
23
18
assertJacocoAndroidWithFlavors(androidAppProject)
24
19
}
25
20
26
21
@Test
27
22
public void addJacocoAndroidLibraryWithFlavors () {
28
-
29
- // Given
30
23
def androidLibraryProject = ProjectHelper . prepare(ANDROID_LIBRARY ). withRedBlueFlavors(). get()
31
24
32
- // When
33
25
Generation . addJacoco(androidLibraryProject, new JunitJacocoExtension ())
34
26
35
- // Then
36
27
assertJacocoAndroidWithFlavors(androidLibraryProject)
37
28
}
38
29
39
30
@Test
40
31
public void addJacocoAndroidApp () {
41
-
42
- // Given
43
32
def androidAppProject = ProjectHelper . prepare(ANDROID_APPLICATION ). get()
44
33
45
- // When
46
34
Generation . addJacoco(androidAppProject, new JunitJacocoExtension ())
47
35
48
- // Then
49
36
assertJacocoAndroidWithoutFlavors(androidAppProject)
50
37
}
51
38
52
39
@Test
53
40
public void addJacocoAndroidLibrary () {
54
-
55
- // Given
56
41
def androidLibraryProject = ProjectHelper . prepare(ANDROID_LIBRARY ). get()
57
42
58
- // When
59
43
Generation . addJacoco(androidLibraryProject, new JunitJacocoExtension ())
60
44
61
- // Then
62
45
assertJacocoAndroidWithoutFlavors(androidLibraryProject)
63
46
}
64
47
65
48
@Test
66
49
public void addJacocoJava () {
67
-
68
- // Given
69
50
def javaProject = ProjectHelper . prepare(JAVA ). get()
70
51
71
- // When
72
52
Generation . addJacoco(javaProject, new JunitJacocoExtension ())
73
53
74
- // Then
75
54
assertJacocoJava(javaProject)
76
55
}
77
56
78
57
@Test
79
58
public void jacocoVersion () {
80
-
81
- // Given
82
59
final def extension = new JunitJacocoExtension ()
83
60
extension. jacocoVersion = ' 0.7.6.201602180812'
84
61
def androidAppProject = ProjectHelper . prepare(ANDROID_APPLICATION ). get()
85
62
def androidLibraryProject = ProjectHelper . prepare(ANDROID_LIBRARY ). get()
86
63
def javaProject = ProjectHelper . prepare(JAVA ). get()
87
64
88
- // When
89
65
Generation . addJacoco(androidAppProject, extension)
90
66
Generation . addJacoco(androidLibraryProject, extension)
91
67
Generation . addJacoco(javaProject, extension)
92
68
93
- // Then
94
69
assert androidAppProject. jacoco. toolVersion == ' 0.7.6.201602180812'
95
70
assert androidLibraryProject. jacoco. toolVersion == ' 0.7.6.201602180812'
96
71
assert javaProject. jacoco. toolVersion == ' 0.7.6.201602180812'
97
72
}
98
73
99
74
@Test
100
75
public void ignoreProjects () {
101
- // Given
102
76
final def extension = new JunitJacocoExtension ()
103
77
final def projects = [
104
78
ProjectHelper . prepare(ANDROID_APPLICATION ). get(),
105
79
ProjectHelper . prepare(ANDROID_LIBRARY ). get(),
106
80
ProjectHelper . prepare(JAVA ). get()] as Project []
107
81
108
82
for (final def project : projects) {
109
- // When
110
83
extension. ignoreProjects = [project. name]
111
84
112
- // Then
113
85
assert ! Generation . addJacoco(project, extension)
114
86
assert ! project. plugins. hasPlugin(JacocoPlugin )
115
87
}
116
88
}
117
89
118
90
@Test
119
91
public void androidAppBuildExecutesJacocoTask () {
120
-
121
- // Given
122
92
def androidAppProject = ProjectHelper . prepare(ANDROID_APPLICATION ). get()
123
93
124
- // When
125
94
Generation . addJacoco(androidAppProject, new JunitJacocoExtension ())
126
95
127
- // Then
128
96
assert taskDependsOn(androidAppProject. check, ' jacocoTestReportDebug' )
129
97
assert taskDependsOn(androidAppProject. check, ' jacocoTestReportRelease' )
130
98
}
131
99
132
100
@Test
133
101
public void androidLibraryBuildExecutesJacocoTask () {
134
-
135
- // Given
136
102
def androidLibraryProject = ProjectHelper . prepare(ANDROID_LIBRARY ). get()
137
103
138
- // When
139
104
Generation . addJacoco(androidLibraryProject, new JunitJacocoExtension ())
140
105
141
- // Then
142
106
assert taskDependsOn(androidLibraryProject. check, ' jacocoTestReportDebug' )
143
107
assert taskDependsOn(androidLibraryProject. check, ' jacocoTestReportRelease' )
144
108
}
145
109
146
110
@Test
147
111
public void javaBuildExecutesJacocoTask () {
148
-
149
- // Given
150
112
def javaProject = ProjectHelper . prepare(JAVA ). get()
151
113
152
- // When
153
114
Generation . addJacoco(javaProject, new JunitJacocoExtension ())
154
115
155
- // Then
156
116
assert taskDependsOn(javaProject. check, ' jacocoTestReport' )
157
117
}
158
118
159
- // TODO some cleanup needed code is almost the same for with and without flavors variants
160
119
private void assertJacocoAndroidWithFlavors (final Project project ) {
161
120
assert project. plugins. hasPlugin(JacocoPlugin )
162
121
163
122
assert project. jacoco. toolVersion == ' 0.7.2.201409121644'
164
123
165
- final def redDebugTask = project. tasks. findByName(' jacocoTestReportRedDebug' )
166
-
167
- assert redDebugTask instanceof JacocoReport
168
-
169
- redDebugTask. with {
170
- assert description == ' Generate Jacoco coverage reports after running redDebug tests.'
171
- assert group == ' Reporting'
172
-
173
- assert executionData. singleFile == project. file(" ${ project.buildDir} /jacoco/testRedDebugUnitTest.exec" )
174
-
175
- assert additionalSourceDirs. size() == 3
176
- assert additionalSourceDirs. contains(project. file(' src/main/java' ))
177
- assert additionalSourceDirs. contains(project. file(' src/debug/java' ))
178
- assert additionalSourceDirs. contains(project. file(' src/red/java' ))
179
-
180
- assert sourceDirectories. size() == 3
181
- assert sourceDirectories. contains(project. file(' src/main/java' ))
182
- assert sourceDirectories. contains(project. file(' src/debug/java' ))
183
- assert sourceDirectories. contains(project. file(' src/red/java' ))
184
-
185
- assert reports. xml. enabled
186
- assert reports. xml. destination. toString() == project. buildDir. absolutePath + ' /reports/jacoco/redDebug/jacoco.xml'
187
- assert reports. html. enabled
188
- assert reports. html. destination. toString() == project. buildDir. absolutePath + ' /reports/jacoco/redDebug'
189
-
190
- assert classDirectories. dir == project. file(' build/intermediates/classes/red/debug' )
191
-
192
- assert taskDependsOn(redDebugTask, ' testRedDebugUnitTest' )
193
- assert taskDependsOn(project. tasks. findByName(' check' ), ' jacocoTestReportRedDebug' )
194
- }
124
+ assertTask(project, ' red' , ' debug' )
125
+ assertTask(project, ' red' , ' release' )
126
+ assertTask(project, ' blue' , ' debug' )
127
+ assertTask(project, ' blue' , ' release' )
128
+ }
195
129
196
- final def blueReleaseTask = project. tasks. findByName(' jacocoTestReportBlueRelease' )
130
+ private void assertTask (final Project project , final String flavor , final String buildType ) {
131
+ final def task = project. tasks. findByName(" jacocoTestReport${ flavor.capitalize()}${ buildType.capitalize()} " )
197
132
198
- assert blueReleaseTask instanceof JacocoReport
133
+ assert task instanceof JacocoReport
199
134
200
- blueReleaseTask . with {
201
- assert description == ' Generate Jacoco coverage reports after running blueRelease tests.'
135
+ task . with {
136
+ assert description == " Generate Jacoco coverage reports after running ${ flavor }${ buildType.capitalize() } tests."
202
137
assert group == ' Reporting'
203
138
204
- assert executionData. singleFile == project. file(" ${ project.buildDir} /jacoco/testBlueReleaseUnitTest .exec" )
139
+ assert executionData. singleFile == project. file(" ${ project.buildDir} /jacoco/test ${ flavor.capitalize() }${ buildType.capitalize() } UnitTest .exec" )
205
140
206
141
assert additionalSourceDirs. size() == 3
207
142
assert additionalSourceDirs. contains(project. file(' src/main/java' ))
208
- assert additionalSourceDirs. contains(project. file(' src/release /java' ))
209
- assert additionalSourceDirs. contains(project. file(' src/blue /java' ))
143
+ assert additionalSourceDirs. contains(project. file(" src/${ buildType } /java" ))
144
+ assert additionalSourceDirs. contains(project. file(" src/${ flavor } /java" ))
210
145
211
146
assert sourceDirectories. size() == 3
212
147
assert sourceDirectories. contains(project. file(' src/main/java' ))
213
- assert sourceDirectories. contains(project. file(' src/release /java' ))
214
- assert sourceDirectories. contains(project. file(' src/blue /java' ))
148
+ assert sourceDirectories. contains(project. file(" src/${ buildType } /java" ))
149
+ assert sourceDirectories. contains(project. file(" src/${ flavor } /java" ))
215
150
216
151
assert reports. xml. enabled
217
- assert reports. xml. destination. toString() == project. buildDir. absolutePath + ' /reports/jacoco/blueRelease /jacoco.xml'
152
+ assert reports. xml. destination. toString() == project. buildDir. absolutePath + " /reports/jacoco/${ flavor }${ buildType.capitalize() } /jacoco.xml"
218
153
assert reports. html. enabled
219
- assert reports. html. destination. toString() == project. buildDir. absolutePath + ' /reports/jacoco/blueRelease '
154
+ assert reports. html. destination. toString() == project. buildDir. absolutePath + " /reports/jacoco/${ flavor }${ buildType.capitalize() } "
220
155
221
- assert classDirectories. dir == project. file(' build/intermediates/classes/blue/release ' )
156
+ assert classDirectories. dir == project. file(" build/intermediates/classes/${ flavor } / ${ buildType } " )
222
157
223
- assert taskDependsOn(blueReleaseTask, ' testBlueReleaseUnitTest ' )
224
- assert taskDependsOn(project. tasks. findByName(' check' ), ' jacocoTestReportBlueRelease ' )
158
+ assert taskDependsOn(task, " test ${ flavor.capitalize() }${ buildType.capitalize() } UnitTest " )
159
+ assert taskDependsOn(project. tasks. findByName(' check' ), " jacocoTestReport ${ flavor.capitalize() }${ buildType.capitalize() } " )
225
160
}
226
161
}
227
162
@@ -289,11 +224,6 @@ public class GenerationTest {
289
224
}
290
225
}
291
226
292
- /**
293
- * Assert proper JAva project construction
294
- *
295
- * @param project
296
- */
297
227
private void assertJacocoJava (final Project project ) {
298
228
assert project. plugins. hasPlugin(JacocoPlugin )
299
229
0 commit comments