@@ -71,7 +71,7 @@ void setUp() throws Exception {
7171
7272 @ Test
7373 void run_withoutJUnit_withOneSplit () throws Exception {
74- final var splits = splitTests (1 , false );
74+ final var splits = splitTests (1 , false , false );
7575 assertThat (splits ).hasSize (1 ).containsExactly ( //
7676 List .of ("de.donnerbart.example.FastTest" ,
7777 "de.donnerbart.example.NoTimingOneTest" ,
@@ -83,7 +83,7 @@ void run_withoutJUnit_withOneSplit() throws Exception {
8383
8484 @ Test
8585 void run_withoutJUnit_withTwoSplits () throws Exception {
86- final var splits = splitTests (2 , false );
86+ final var splits = splitTests (2 , false , false );
8787 assertThat (splits ).hasSize (2 ).containsExactly ( //
8888 List .of ("de.donnerbart.example.FastTest" ,
8989 "de.donnerbart.example.NoTimingTwoTest" ,
@@ -94,7 +94,7 @@ void run_withoutJUnit_withTwoSplits() throws Exception {
9494
9595 @ Test
9696 void run_withoutJUnit_withThreeSplits () throws Exception {
97- final var splits = splitTests (3 , false );
97+ final var splits = splitTests (3 , false , false );
9898 assertThat (splits ).hasSize (3 ).containsExactly ( //
9999 List .of ("de.donnerbart.example.FastTest" , "de.donnerbart.example.SlowTest" ),
100100 List .of ("de.donnerbart.example.NoTimingOneTest" , "de.donnerbart.example.SlowestTest" ),
@@ -104,7 +104,7 @@ void run_withoutJUnit_withThreeSplits() throws Exception {
104104
105105 @ Test
106106 void run_withoutJUnit_withThreeSplits_withGradleFormat () throws Exception {
107- final var splits = splitTests (3 , false , "**/example-project/**/*Test.java" , tmp , FormatOption .GRADLE );
107+ final var splits = splitTests (3 , false , "**/example-project/**/*Test.java" , false , tmp , FormatOption .GRADLE );
108108 assertThat (splits ).hasSize (3 ).containsExactly ( //
109109 List .of ("--tests de.donnerbart.example.FastTest" , "--tests de.donnerbart.example.SlowTest" ),
110110 List .of ("--tests de.donnerbart.example.NoTimingOneTest" , "--tests de.donnerbart.example.SlowestTest" ),
@@ -114,7 +114,7 @@ void run_withoutJUnit_withThreeSplits_withGradleFormat() throws Exception {
114114
115115 @ Test
116116 void run_withJUnit_withOneSplit () throws Exception {
117- final var splits = splitTests (1 , true );
117+ final var splits = splitTests (1 , true , false );
118118 assertThat (splits ).hasSize (1 ).containsExactly ( //
119119 List .of ("de.donnerbart.example.SlowestTest" ,
120120 "de.donnerbart.example.SlowTest" ,
@@ -126,7 +126,7 @@ void run_withJUnit_withOneSplit() throws Exception {
126126
127127 @ Test
128128 void run_withJUnit_withTwoSplits () throws Exception {
129- final var splits = splitTests (2 , true );
129+ final var splits = splitTests (2 , true , false );
130130 assertThat (splits ).hasSize (2 ).containsExactly ( //
131131 List .of ("de.donnerbart.example.SlowestTest" ),
132132 List .of ("de.donnerbart.example.SlowTest" ,
@@ -138,7 +138,7 @@ void run_withJUnit_withTwoSplits() throws Exception {
138138
139139 @ Test
140140 void run_withJUnit_withThreeSplits () throws Exception {
141- final var splits = splitTests (3 , true );
141+ final var splits = splitTests (3 , true , false );
142142 assertThat (splits ).hasSize (3 ).containsExactly ( //
143143 List .of ("de.donnerbart.example.SlowestTest" ),
144144 List .of ("de.donnerbart.example.SlowTest" ),
@@ -150,7 +150,7 @@ void run_withJUnit_withThreeSplits() throws Exception {
150150
151151 @ Test
152152 void run_withJUnit_withFourSplits () throws Exception {
153- final var splits = splitTests (4 , true );
153+ final var splits = splitTests (4 , true , false );
154154 assertThat (splits ).hasSize (4 ).containsExactly ( //
155155 List .of ("de.donnerbart.example.SlowestTest" ),
156156 List .of ("de.donnerbart.example.SlowTest" ),
@@ -159,6 +159,51 @@ void run_withJUnit_withFourSplits() throws Exception {
159159 assertThat (exitCode ).hasNullValue ();
160160 }
161161
162+ @ Test
163+ void run_withJUnit_withAverageTestTime_withOneSplit () throws Exception {
164+ final var splits = splitTests (1 , true , true );
165+ assertThat (splits ).hasSize (1 ).containsExactly ( //
166+ List .of ("de.donnerbart.example.SlowestTest" ,
167+ "de.donnerbart.example.NoTimingOneTest" ,
168+ "de.donnerbart.example.NoTimingTwoTest" ,
169+ "de.donnerbart.example.SlowTest" ,
170+ "de.donnerbart.example.FastTest" ));
171+ assertThat (exitCode ).hasNullValue ();
172+ }
173+
174+ @ Test
175+ void run_withJUnit_withAverageTestTime_withTwoSplits () throws Exception {
176+ final var splits = splitTests (2 , true , true );
177+ assertThat (splits ).hasSize (2 ).containsExactly ( //
178+ List .of ("de.donnerbart.example.SlowestTest" ),
179+ List .of ("de.donnerbart.example.NoTimingOneTest" ,
180+ "de.donnerbart.example.NoTimingTwoTest" ,
181+ "de.donnerbart.example.SlowTest" ,
182+ "de.donnerbart.example.FastTest" ));
183+ assertThat (exitCode ).hasNullValue ();
184+ }
185+
186+ @ Test
187+ void run_withJUnit_withAverageTestTime_withThreeSplits () throws Exception {
188+ final var splits = splitTests (3 , true , true );
189+ assertThat (splits ).hasSize (3 ).containsExactly ( //
190+ List .of ("de.donnerbart.example.SlowestTest" ),
191+ List .of ("de.donnerbart.example.NoTimingOneTest" , "de.donnerbart.example.SlowTest" ),
192+ List .of ("de.donnerbart.example.NoTimingTwoTest" , "de.donnerbart.example.FastTest" ));
193+ assertThat (exitCode ).hasNullValue ();
194+ }
195+
196+ @ Test
197+ void run_withJUnit_withAverageTestTime_withFourSplits () throws Exception {
198+ final var splits = splitTests (4 , true , true );
199+ assertThat (splits ).hasSize (4 ).containsExactly ( //
200+ List .of ("de.donnerbart.example.SlowestTest" ),
201+ List .of ("de.donnerbart.example.NoTimingOneTest" ),
202+ List .of ("de.donnerbart.example.NoTimingTwoTest" ),
203+ List .of ("de.donnerbart.example.SlowTest" , "de.donnerbart.example.FastTest" ));
204+ assertThat (exitCode ).hasNullValue ();
205+ }
206+
162207 @ Test
163208 void run_whitespaceClassDefinition () throws Exception {
164209 final var projectFolder =
@@ -174,6 +219,7 @@ void run_whitespaceClassDefinition() throws Exception {
174219 null ,
175220 null ,
176221 FormatOption .LIST ,
222+ false ,
177223 projectFolder ,
178224 true ,
179225 exitCode ::set );
@@ -191,8 +237,12 @@ void run_thirdPartyLibrary() throws Exception {
191237 "ThirdPartyLibraryTest.java" ,
192238 PERMISSIONS );
193239
194- final var splits =
195- splitTests (1 , false , "**/third-party-library-project/**/*Test.java" , projectFolder , FormatOption .LIST );
240+ final var splits = splitTests (1 ,
241+ false ,
242+ "**/third-party-library-project/**/*Test.java" ,
243+ false ,
244+ projectFolder ,
245+ FormatOption .LIST );
196246 assertThat (splits ).hasSize (1 ).containsExactly (List .of ("de.donnerbart.example.ThirdPartyLibraryTest" ));
197247 assertThat (exitCode ).hasNullValue ();
198248 }
@@ -203,7 +253,7 @@ void run_noPackage() throws Exception {
203253 copyResourceToTarget (projectFolder , "tests/NoPackageTest.java" , "NoPackageTest.java" , PERMISSIONS );
204254
205255 final var splits =
206- splitTests (1 , false , "**/no-package-project/**/*Test.java" , projectFolder , FormatOption .LIST );
256+ splitTests (1 , false , "**/no-package-project/**/*Test.java" , false , projectFolder , FormatOption .LIST );
207257 assertThat (splits ).hasSize (1 ).containsExactly (List .of ("NoPackageTest" ));
208258 assertThat (exitCode ).hasNullValue ();
209259 }
@@ -213,7 +263,19 @@ void run_noTests() throws Exception {
213263 final var projectFolder = tmp .resolve ("no-tests-project" ).resolve ("src" ).resolve ("main" ).resolve ("java" );
214264 Files .createDirectories (projectFolder );
215265
216- final var splits = splitTests (1 , false , "**/no-tests-project/**/*Test.java" , projectFolder , FormatOption .LIST );
266+ final var splits =
267+ splitTests (1 , false , "**/no-tests-project/**/*Test.java" , false , projectFolder , FormatOption .LIST );
268+ assertThat (splits ).hasSize (1 ).containsExactly (List .of ());
269+ assertThat (exitCode ).hasValue (1 );
270+ }
271+
272+ @ Test
273+ void run_noTests_withAverageTestTime () throws Exception {
274+ final var projectFolder = tmp .resolve ("no-tests-project" ).resolve ("src" ).resolve ("main" ).resolve ("java" );
275+ Files .createDirectories (projectFolder );
276+
277+ final var splits =
278+ splitTests (1 , false , "**/no-tests-project/**/*Test.java" , true , projectFolder , FormatOption .LIST );
217279 assertThat (splits ).hasSize (1 ).containsExactly (List .of ());
218280 assertThat (exitCode ).hasValue (1 );
219281 }
@@ -224,19 +286,28 @@ void run_noClassName() throws Exception {
224286 copyResourceToTarget (projectFolder , "tests/NoClassNameTest.java" , "NoClassNameTest.java" , PERMISSIONS );
225287
226288 final var splits =
227- splitTests (1 , false , "**/no-classname-project/**/*Test.java" , projectFolder , FormatOption .LIST );
289+ splitTests (1 , false , "**/no-classname-project/**/*Test.java" , false , projectFolder , FormatOption .LIST );
228290 assertThat (splits ).hasSize (1 ).containsExactly (List .of ());
229291 assertThat (exitCode ).hasValue (1 );
230292 }
231293
232- private @ NotNull List <List <String >> splitTests (final int splitTotal , final boolean withJUnit ) throws Exception {
233- return splitTests (splitTotal , withJUnit , "**/example-project/**/*Test.java" , tmp , FormatOption .LIST );
294+ private @ NotNull List <List <String >> splitTests (
295+ final int splitTotal ,
296+ final boolean withJUnit ,
297+ final boolean useAverageTimeForNewTests ) throws Exception {
298+ return splitTests (splitTotal ,
299+ withJUnit ,
300+ "**/example-project/**/*Test.java" ,
301+ useAverageTimeForNewTests ,
302+ tmp ,
303+ FormatOption .LIST );
234304 }
235305
236306 private @ NotNull List <List <String >> splitTests (
237307 final int splitTotal ,
238308 final boolean withJUnit ,
239309 final @ NotNull String glob ,
310+ final boolean useAverageTimeForNewTests ,
240311 final @ NotNull Path workingDir ,
241312 final @ NotNull FormatOption format ) throws Exception {
242313 final var splits = new ArrayList <List <String >>();
@@ -247,6 +318,7 @@ void run_noClassName() throws Exception {
247318 "**/example-project/**/*Abstract*.java" ,
248319 withJUnit ? "**/junit-reports/*.xml" : null ,
249320 format ,
321+ useAverageTimeForNewTests ,
250322 workingDir ,
251323 true ,
252324 exitCode ::set );
0 commit comments