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
public class ReportingState { | |
private final Map<String, String> results = new ConcurrentHashMap<>(); | |
public void addResult(String testName, String result) { | |
results.put(testName, result); | |
} | |
public void report() { | |
System.out.println("---- Test Results ----"); | |
results.forEach((testName, result) -> { |
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
@ExtendWith(ReportingExtension.class) | |
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { | |
// We need to enable lazy initialization to avoid the EntityManager creation during the context loading | |
"spring.main.lazy-initialization=true" | |
}) | |
public class MetricsTests { | |
@Autowired | |
TestRestTemplate testRestTemplate; |
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
public class ReportingExtension implements TestWatcher, BeforeEachCallback, AfterAllCallback, ParameterResolver { | |
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace.create(ReportingExtension.class); | |
private static final String REPORTING_STATE_KEY = "reportingState"; | |
@Override | |
public void beforeEach(ExtensionContext context) throws Exception { | |
// Store the start time for the test | |
context.getStore(NAMESPACE).put("startTime", System.currentTimeMillis()); | |
} |
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
@ExtendWith({ | |
PostgreSQLExtension.class, | |
ReportingExtension.class | |
}) | |
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { | |
// We need to enable lazy initialization to avoid the EntityManager creation during the context loading | |
"spring.main.lazy-initialization=true" | |
}) | |
class CleanTimingTest { | |
@Autowired |
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
public class ReportingExtension implements TestWatcher, BeforeEachCallback { | |
private long startTime; | |
@Override | |
public void testDisabled(ExtensionContext context, java.util.Optional<String> reason) { | |
System.out.println(context.getDisplayName() + " DISABLED" + reason.map(r -> ": " + r).orElse("")); | |
} | |
@Override | |
public void testSuccessful(ExtensionContext context) { |
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
class ManuallyTimingTest { | |
private long startTime; | |
@BeforeEach | |
void startTimer() { | |
startTime = System.currentTimeMillis(); | |
} | |
@AfterEach |
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
@ExtendWith(SQLiteExtension.class) | |
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { | |
// We need to enable lazy initialization to avoid the EntityManager creation during the context loading | |
"spring.main.lazy-initialization=true" | |
}) | |
class CleanSQLiteTest { | |
@Autowired | |
EntityManager entityManager; | |
@Test |
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
public class SQLiteExtension implements BeforeAllCallback, AfterAllCallback { | |
static String uniqueDbName = "memdb" + UUID.randomUUID(); | |
private static final String JDBC_URL = "jdbc:sqlite:file:" + uniqueDbName + "?mode=memory&cache=shared"; | |
private Connection connection; | |
@Override | |
public void beforeAll(ExtensionContext context) throws Exception { | |
// Set system properties |
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
@ExtendWith(PostgreSQLExtension.class) | |
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { | |
// We need to enable lazy initialization to avoid the EntityManager creation during the context loading | |
"spring.main.lazy-initialization=true" | |
}) | |
class CleanPostgreSQLTest { | |
@Autowired | |
EntityManager entityManager; | |
@Test |
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
public class PostgreSQLExtension implements BeforeAllCallback, AfterAllCallback { | |
private static PostgreSQLContainer<?> postgres; | |
@Override | |
@SneakyThrows | |
public void beforeAll(ExtensionContext context) { | |
// Start the PostgreSQL container | |
postgres = new PostgreSQLContainer<>("postgres:latest") | |
.withDatabaseName("testdb") |
NewerOlder