You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+153Lines changed: 153 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -105,3 +105,156 @@ public class ClassUnderTest {
105
105
}
106
106
```
107
107
108
+
### Using `@InTestsUseClasses`
109
+
110
+
The `@InTestsUseClasses` annotation allows the user to recommend specific `Class` literal values to use in tests.
111
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
112
+
For example the following method is annotated with an example class literal to achieve a positive test:
The `@InTestsUseStrings` annotation allows the user to recommend specific `String` values to use in tests.
123
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
124
+
For example the following method is annotated with some genuine examples of song titles that can be used to achieve coverage:
125
+
126
+
```java
127
+
publicstaticboolean isDayRelatedSongTitle(@InTestsUseStrings({"I Don't Like Mondays", "Here Comes The Weekend"}) String title) {
128
+
returnStream.of(DayOfWeek.values())
129
+
.map(DayOfWeek::name)
130
+
.map(String::toLowerCase)
131
+
.anyMatch(title.toLowerCase()::contains);
132
+
}
133
+
```
134
+
135
+
### Using `@InTestsUseCharacters`
136
+
137
+
The `@InTestsUseCharacters` annotation allows the user to recommend specific `char` values to use in tests.
138
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
139
+
For example the following method is annotated with a genuine examples characters that make up a Unicode surrogate pair that can be used to achieve a positive test:
140
+
141
+
```java
142
+
@Nullable
143
+
publicstaticInteger toNullableCodePoint(
144
+
@InTestsUseCharacters('\uD801') char high,
145
+
@InTestsUseCharacters('\uDC37') char low) {
146
+
if (Character.isSurrogatePair(high, low)) {
147
+
returnCharacter.toCodePoint(high, low);
148
+
}
149
+
returnnull;
150
+
}
151
+
```
152
+
153
+
### Using `@InTestsUseBytes`
154
+
155
+
The `@InTestsUseBytes` annotation allows the user to recommend specific `byte` values to use in tests.
156
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
157
+
For example the following method is annotated to use a specific preferred value:
The `@InTestsUseShorts` annotation allows the user to recommend specific `short` values to use in tests.
168
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
169
+
For example the following method is annotated to use a specific preferred value:
170
+
171
+
```java
172
+
publicstaticString toUpperHexString(@InTestsUseShorts((short)0xD1FF) short input) {
173
+
returnLong.toHexString(input).toUpperCase();
174
+
}
175
+
```
176
+
177
+
### Using `@InTestsUseIntegers`
178
+
179
+
The `@InTestsUseIntegers` annotation allows the user to recommend specific `int` values to use in tests.
180
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
181
+
For example the following method is annotated to use a specific preferred value:
182
+
183
+
```java
184
+
publicstaticString toUpperHexString(@InTestsUseIntegers(0xD1FFB) int input) {
185
+
returnLong.toHexString(input).toUpperCase();
186
+
}
187
+
```
188
+
189
+
### Using `@InTestsUseLongs`
190
+
191
+
The `@InTestsUseLongs` annotation allows the user to recommend specific `long` values to use in tests.
192
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
193
+
For example the following method is annotated to use a specific preferred value:
194
+
195
+
```java
196
+
publicstaticString toUpperHexString(@InTestsUseLongs(0xD1FFBL) long input) {
197
+
returnLong.toHexString(input).toUpperCase();
198
+
}
199
+
```
200
+
201
+
### Using `@InTestsUseFloats`
202
+
203
+
The `@InTestsUseFloats` annotation allows the user to recommend specific `float` values to use in tests.
204
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
205
+
For example the following method is annotated to use a specific preferred value:
The `@InTestsUseDoubles` annotation allows the user to recommend specific `double` values to use in tests.
216
+
Sometimes this can be useful to control the values used for cosmetic reasons, but it can also be useful when Cover is unable to identify values to cover all cases.
217
+
For example the following method is annotated to use a specific preferred value:
Indicates the annotated method as a useful factory method for use in tests.
228
+
Cover will automatically recognise factory methods that simply return a newly created instance, but may not identify more complicated factories.
229
+
This annotation allows such factory methods to be manually annotated so that Cover considers them for producing inputs.
230
+
For example the following method under test takes a `User` as input, but the `User` constructor is private and Cover doesn't naturally consider `ofStaff(String)` to be a safe factory method to call.
231
+
By annotating the `ofStaff(String)` with `@InterstingTestFactory` we can tell Cover that this should be considered a good factory method to use in tests.
0 commit comments