Hola
En una pasantía reciente de Spring 5 / JPA Enterprise (Topjava), nuestro proyecto de capacitación migró de JUnit 4 a JUnit 5.2. El proceso principal de migración es bastante sencillo, pero hay algunos matices que requieren intervención manual. Quiero hablar brevemente sobre ellos y la creación de Extensiones JUnit 5 para medir el tiempo de las pruebas en un video de 10 minutos.
Código de extensión para medir el tiempo de pruebaimport org.junit.jupiter.api.extension.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.StopWatch; public class TimingExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeAllCallback, AfterAllCallback { private static final Logger log = LoggerFactory.getLogger("result"); private StopWatch stopWatch; @Override public void beforeAll(ExtensionContext ctx) { stopWatch = new StopWatch("Execution time of " + ctx.getRequiredTestClass().getSimpleName()); } @Override public void beforeTestExecution(ExtensionContext ctx) { log.info("Start stopWatch"); stopWatch.start(ctx.getDisplayName()); } @Override public void afterTestExecution(ExtensionContext ctx) { stopWatch.stop(); log.info("stop stopWatch"); } @Override public void afterAll(ExtensionContext ctx) { log.info('\n' + stopWatch.prettyPrint() + '\n'); } }
Enlaces utiles:
Gracias por su atencion!
Espero que si su proyecto usa JUnit 4 y aún no ha migrado a JUnit 5, este breve video lo inspirará. Y también sobre el uso de JUnit 5 en sus nuevos proyectos.