Commit
…parameterized tests
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
package org.apache.maven.surefire.util.internal;/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */import java.util.regex.Matcher;import java.util.regex.Pattern;/** * JUnit Description parser. * Used by JUnit Version lower than 4.7. * * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a> * @since 2.20 */public final class TestClassMethodNameUtils{ private static final Pattern METHOD_CLASS_PATTERN = Pattern.compile( "([\\s\\S]*)\\((.*)\\)" ); private TestClassMethodNameUtils() { throw new IllegalStateException( "no instantiable constructor" ); } public static String extractClassName( String displayName ) { Matcher m = METHOD_CLASS_PATTERN.matcher( displayName ); return m.matches() ? m.group( 2 ) : displayName; } public static String extractMethodName( String displayName ) { int i = displayName.indexOf( "(" ); return i >= 0 ? displayName.substring( 0, i ) : displayName; }} | ||
package org.apache.maven.surefire.util.internal; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* JUnit Description parser. | ||
* Used by JUnit Version lower than 4.7. | ||
* | ||
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a> | ||
* @since 2.20 | ||
*/ | ||
public final class TestClassMethodNameUtils | ||
{ | ||
private static final Pattern METHOD_CLASS_PATTERN = Pattern.compile( "([\\s\\S]*)\\((.*)\\)" ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Tibor17
Contributor
|
||
|
||
private TestClassMethodNameUtils() | ||
{ | ||
throw new IllegalStateException( "no instantiable constructor" ); | ||
} | ||
|
||
public static String extractClassName( String displayName ) | ||
{ | ||
Matcher m = METHOD_CLASS_PATTERN.matcher( displayName ); | ||
return m.matches() ? m.group( 2 ) : displayName; | ||
} | ||
|
||
public static String extractMethodName( String displayName ) | ||
{ | ||
Matcher m = METHOD_CLASS_PATTERN.matcher( displayName ); | ||
return m.matches() ? m.group( 1 ) : null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,17 +23,22 @@ | |
import org.apache.maven.surefire.its.fixture.OutputValidator; | ||
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; | ||
import org.apache.maven.surefire.its.fixture.SurefireLauncher; | ||
import org.apache.maven.surefire.its.fixture.TestFile; | ||
import org.hamcrest.BaseMatcher; | ||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.junit.Test; | ||
|
||
import java.nio.charset.Charset; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
||
import static org.hamcrest.core.AnyOf.anyOf; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.StringContains.containsString; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
|
@@ -44,17 +49,29 @@ | |
public class Surefire1082ParallelJUnitParameterizedIT | ||
extends SurefireJUnit4IntegrationTestCase | ||
{ | ||
private static Set<String> printOnlyTestLinesFromConsole( OutputValidator validator ) | ||
throws VerificationException | ||
{ | ||
return printOnlyTestLines( validator.loadLogLines() ); | ||
} | ||
|
||
private static Set<String> printOnlyTestLinesFromOutFile( OutputValidator validator ) | ||
throws VerificationException | ||
{ | ||
TestFile report = validator.getSurefireReportsFile( "jiras.surefire1082.Jira1082Test-output.txt" ); | ||
report.assertFileExists(); | ||
return printOnlyTestLines( validator.loadFile( report.getFile(), Charset.forName( "UTF-8" ) ) ); | ||
} | ||
|
||
private static Set<String> printOnlyTestLines( OutputValidator validator ) | ||
private static Set<String> printOnlyTestLines( Collection<String> logs ) | ||
throws VerificationException | ||
{ | ||
Set<String> log = new TreeSet<String>( validator.loadLogLines() ); | ||
for ( Iterator<String> it = log.iterator(); it.hasNext(); ) | ||
SortedSet<String> log = new TreeSet<String>(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Tibor17
Contributor
|
||
for ( String line : logs ) | ||
{ | ||
String line = it.next(); | ||
if ( !line.startsWith( "class jiras.surefire1082." ) ) | ||
if ( line.startsWith( "class jiras.surefire1082." ) ) | ||
{ | ||
it.remove(); | ||
log.add( line ); | ||
} | ||
} | ||
return log; | ||
|
@@ -65,14 +82,8 @@ private static Matcher<Set<String>> regex( Set<String> r ) | |
return new IsRegex( r ); | ||
} | ||
|
||
@Test | ||
public void test() | ||
throws VerificationException | ||
private static void assertParallelRun( Set<String> log ) | ||
{ | ||
OutputValidator validator = unpack().setTestToRun( | ||
"Jira1082Test" ).parallelClasses().useUnlimitedThreads().executeTest().verifyErrorFree( 4 ); | ||
|
||
Set<String> log = printOnlyTestLines( validator ); | ||
assertThat( log.size(), is( 4 ) ); | ||
|
||
Set<String> expectedLogs1 = new TreeSet<String>(); | ||
|
@@ -90,6 +101,71 @@ public void test() | |
assertThat( log, anyOf( regex( expectedLogs1 ), regex( expectedLogs2 ) ) ); | ||
} | ||
|
||
@Test | ||
public void checkClassesRunParallel() | ||
throws VerificationException | ||
{ | ||
OutputValidator validator = unpack().setTestToRun( "Jira1082Test" ) | ||
.parallelClasses() | ||
.useUnlimitedThreads() | ||
.executeTest() | ||
.verifyErrorFree( 4 ); | ||
|
||
validator.getSurefireReportsXmlFile( "TEST-jiras.surefire1082.Jira1082Test.xml" ) | ||
.assertFileExists(); | ||
|
||
validator.assertThatLogLine( containsString( "Running jiras.surefire1082.Jira1082Test" ), is( 1 ) ); | ||
|
||
Set<String> log = printOnlyTestLinesFromConsole( validator ); | ||
assertParallelRun( log ); | ||
} | ||
|
||
@Test | ||
public void checkOutFileClassesRunParallel() | ||
throws VerificationException | ||
{ | ||
OutputValidator validator = unpack().redirectToFile( true ) | ||
.setTestToRun( "Jira1082Test" ) | ||
.parallelClasses() | ||
.useUnlimitedThreads() | ||
.executeTest() | ||
.verifyErrorFree( 4 ); | ||
|
||
validator.getSurefireReportsXmlFile( "TEST-jiras.surefire1082.Jira1082Test.xml" ) | ||
.assertFileExists(); | ||
|
||
validator.assertThatLogLine( containsString( "Running jiras.surefire1082.Jira1082Test" ), is( 1 ) ); | ||
|
||
Set<String> log = printOnlyTestLinesFromOutFile( validator ); | ||
assertParallelRun( log ); | ||
} | ||
|
||
@Test | ||
public void shouldRunTwo() throws VerificationException | ||
{ | ||
OutputValidator validator = unpack().redirectToFile( true ) | ||
.parallelClasses() | ||
.useUnlimitedThreads() | ||
.executeTest() | ||
.verifyErrorFree( 8 ); | ||
|
||
validator.getSurefireReportsXmlFile( "TEST-jiras.surefire1082.Jira1082Test.xml" ) | ||
.assertFileExists(); | ||
|
||
validator.getSurefireReportsXmlFile( "TEST-jiras.surefire1082.Jira1264Test.xml" ) | ||
.assertFileExists(); | ||
|
||
validator.getSurefireReportsFile( "jiras.surefire1082.Jira1082Test-output.txt" ) | ||
.assertFileExists(); | ||
|
||
validator.getSurefireReportsFile( "jiras.surefire1082.Jira1264Test-output.txt" ) | ||
.assertFileExists(); | ||
|
||
validator.assertThatLogLine( containsString( "Running jiras.surefire1082.Jira1082Test" ), is( 1 ) ); | ||
|
||
validator.assertThatLogLine( containsString( "Running jiras.surefire1082.Jira1264Test" ), is( 1 ) ); | ||
} | ||
|
||
private SurefireLauncher unpack() | ||
{ | ||
return unpack( "surefire-1082-parallel-junit-parameterized" ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package jiras.surefire1082; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Arrays; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@RunWith( Parameterized.class ) | ||
public final class Jira1264Test extends Jira1082Test | ||
{ | ||
public Jira1264Test( int x ) | ||
{ | ||
super( x ); | ||
} | ||
} |
1 comment
on commit 92b39d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost fine expect a small few things.
That's a weird pattern:
\s\S*
. That's basically.*
. Is that really correct?