-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up JUnit 5 support discovery process #881
The JUnit platform API makes it necessary for ArchUnit to provide an implementation to discover test classes from the classpath (e.g. because the discovery request contains a package selector). Since ArchUnit itself is perfectly suited for this and does not demand any third party dependency we simply use the `ClassFileImporter` for this. However, so far we have used the current `ArchConfiguration` of the user, which by default e.g. resolves all further dependencies from the classpath. This is unnecessary overhead and can substantially slow down the discovery process if the test classes e.g. have some framework dependencies like the Spring framework. We will now switch the `ArchConfiguration` for the discovery process so that it does not import any transitive dependencies of the discovered classes. This way the discovery process via ArchUnit should be quite fast, no matter what further dependencies the test classes have.
- Loading branch information
Showing
11 changed files
with
412 additions
and
122 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
23 changes: 23 additions & 0 deletions
23
...t/junit5/engine/src/test/java/com/tngtech/archunit/junit/internal/testutil/LogCaptor.java
This file contains 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,23 @@ | ||
package com.tngtech.archunit.junit.internal.testutil; | ||
|
||
import java.util.List; | ||
|
||
import com.tngtech.archunit.testutil.TestLogRecorder; | ||
import com.tngtech.archunit.testutil.TestLogRecorder.RecordedLogEvent; | ||
import org.apache.logging.log4j.Level; | ||
|
||
public class LogCaptor { | ||
private final TestLogRecorder logRecorder = new TestLogRecorder(); | ||
|
||
public void watch(Class<?> loggerClass, Level level) { | ||
logRecorder.record(loggerClass, level); | ||
} | ||
|
||
public void cleanUp() { | ||
logRecorder.reset(); | ||
} | ||
|
||
public List<RecordedLogEvent> getEvents(Level level) { | ||
return logRecorder.getEvents(level); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...5/engine/src/test/java/com/tngtech/archunit/junit/internal/testutil/TestLogExtension.java
This file contains 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,26 @@ | ||
package com.tngtech.archunit.junit.internal.testutil; | ||
|
||
import org.junit.jupiter.api.extension.AfterEachCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ParameterContext; | ||
import org.junit.jupiter.api.extension.ParameterResolutionException; | ||
import org.junit.jupiter.api.extension.ParameterResolver; | ||
|
||
public class TestLogExtension implements ParameterResolver, AfterEachCallback { | ||
private final LogCaptor logCaptor = new LogCaptor(); | ||
|
||
@Override | ||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | ||
return LogCaptor.class.equals(parameterContext.getParameter().getType()); | ||
} | ||
|
||
@Override | ||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { | ||
return logCaptor; | ||
} | ||
|
||
@Override | ||
public void afterEach(ExtensionContext context) { | ||
logCaptor.cleanUp(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.