-
Notifications
You must be signed in to change notification settings - Fork 557
Tests runorder #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Tests runorder #492
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
...ire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderOrderingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| package org.apache.maven.surefire.junit4; | ||
|
|
||
| /* | ||
| * 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.apache.maven.surefire.api.booter.BaseProviderFactory; | ||
| import org.apache.maven.surefire.api.report.ReporterFactory; | ||
| import org.apache.maven.surefire.api.report.TestOutputReportEntry; | ||
| import org.apache.maven.surefire.api.report.TestReportListener; | ||
| import org.apache.maven.surefire.api.suite.RunResult; | ||
| import org.apache.maven.surefire.api.testset.RunOrderParameters; | ||
| import org.apache.maven.surefire.api.testset.TestListResolver; | ||
| import org.apache.maven.surefire.api.testset.TestRequest; | ||
| import org.apache.maven.surefire.api.testset.TestSetFailedException; | ||
| import org.apache.maven.surefire.api.util.TestsToRun; | ||
| import org.junit.Test; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static java.util.Arrays.asList; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| /** | ||
| * @author Aslak Hellesøy | ||
| */ | ||
| public class JUnit4ProviderOrderingTest | ||
| { | ||
| /** | ||
| */ | ||
| public static class TestX | ||
| { | ||
| @Test | ||
| public void testA() | ||
| { | ||
| } | ||
|
|
||
| @Test | ||
| public void testB() | ||
| { | ||
| } | ||
|
|
||
| @Test | ||
| public void testC() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| */ | ||
| public static class TestY | ||
| { | ||
| @Test | ||
| public void testD() | ||
| { | ||
| } | ||
|
|
||
| @Test | ||
| public void testE() | ||
| { | ||
| } | ||
|
|
||
| @Test | ||
| public void testF() | ||
| { | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void testShouldOrderWithinSingleTestClass() throws TestSetFailedException | ||
| { | ||
| assertTestOrder( | ||
| TestX.class.getName() + "#testC", | ||
| TestX.class.getName() + "#testA", | ||
| TestX.class.getName() + "#testB" | ||
| ); | ||
| } | ||
|
|
||
| private void assertTestOrder( String... tests ) throws TestSetFailedException | ||
| { | ||
| List<String> testOrder = asList( tests ); | ||
| BaseProviderFactory providerParameters = new BaseProviderFactory( true ); | ||
| providerParameters.setProviderProperties( new HashMap<>() ); | ||
| providerParameters.setClassLoaders( getClass().getClassLoader() ); | ||
| TestListResolver requestedTests = new TestListResolver( String.join( ",", testOrder ) ); | ||
| TestRequest testRequest = new TestRequest( null, null, requestedTests ); | ||
| providerParameters.setTestRequest( testRequest ); | ||
| providerParameters.setRunOrderParameters( RunOrderParameters.alphabetical() ); | ||
|
|
||
| MockReporter testReportListener = new MockReporter(); | ||
| providerParameters.setReporterFactory( new StubReporterFactory( testReportListener ) ); | ||
| JUnit4Provider provider = new JUnit4Provider( providerParameters ); | ||
| TestsToRun testsToRun = new TestsToRun( new HashSet<>( asList( TestX.class, TestY.class ) ) ); | ||
| provider.invoke( testsToRun ); | ||
|
|
||
| List<String> actualOrder = testReportListener.getReports().stream() | ||
| .map( r -> String.format( "%s#%s", r.getSourceName(), r.getName() ) ) | ||
| .collect( Collectors.toList() ); | ||
|
|
||
| assertThat( actualOrder, is( testOrder ) ); | ||
| } | ||
|
|
||
| private static class StubReporterFactory implements ReporterFactory | ||
| { | ||
| private final TestReportListener<TestOutputReportEntry> testReportListener; | ||
|
|
||
| private StubReporterFactory( TestReportListener<TestOutputReportEntry> testReportListener ) | ||
| { | ||
| this.testReportListener = testReportListener; | ||
| } | ||
|
|
||
| @Override | ||
| public TestReportListener<TestOutputReportEntry> createTestReportListener() | ||
| { | ||
| return testReportListener; | ||
| } | ||
|
|
||
| @Override | ||
| public RunResult close() | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
| } |
147 changes: 147 additions & 0 deletions
147
...roviders/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/MockReporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| package org.apache.maven.surefire.junit4; | ||
|
|
||
| /* | ||
| * 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.apache.maven.surefire.api.report.ReportEntry; | ||
| import org.apache.maven.surefire.api.report.TestOutputReportEntry; | ||
| import org.apache.maven.surefire.api.report.TestReportListener; | ||
| import org.apache.maven.surefire.api.report.TestSetReportEntry; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Internal tests use only. | ||
| */ | ||
| final class MockReporter | ||
| implements TestReportListener<TestOutputReportEntry> | ||
| { | ||
| private final List<ReportEntry> reports = new ArrayList<>(); | ||
|
|
||
| @Override | ||
| public void testSetStarting( TestSetReportEntry report ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void testSetCompleted( TestSetReportEntry report ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void testStarting( ReportEntry report ) | ||
| { | ||
| reports.add( report ); | ||
| } | ||
|
|
||
| @Override | ||
| public void testSucceeded( ReportEntry report ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void testSkipped( ReportEntry report ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void testExecutionSkippedByUser() | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void testError( ReportEntry report ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void testFailed( ReportEntry report ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void testAssumptionFailure( ReportEntry report ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTestOutput( TestOutputReportEntry reportEntry ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isDebugEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void debug( String message ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isInfoEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void info( String message ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isWarnEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void warning( String message ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isErrorEnabled() | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public void error( String message ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void error( String message, Throwable t ) | ||
| { | ||
| } | ||
|
|
||
| @Override | ||
| public void error( Throwable t ) | ||
| { | ||
| } | ||
|
|
||
| public List<ReportEntry> getReports() | ||
| { | ||
| return reports; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
If you do something like this, you are on wrong way.
The problem is that you wanted to get to the end within one day, and that's the problem.
You should follow those 5 steps, you would not get to the end after you have implemented first 4 steps but would would do 85% of your work without removing anything.
If you are not sure in the beginning, it is still right way to write an integration test because it is always needed and it is the vision you want to emphase to everyone.
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.
Thanks, I will close this PR and send another one. I've also written up a JIRA issue explaining a bit more about the motivation: https://issues.apache.org/jira/browse/SUREFIRE-2041
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.
Please see #495 for my take II on this issue.