Migration of the Topjava training project to JUnit 5 in 10 min. Measurement of test time with Extensions
Hello!
On the last Spring 5 /JPA Enterprise (Topjava) internship our training project migrated from JUnit 4 to JUnit 5.2. The basic process of migration is straightforward enough, but there are some nuances that require manual intervention. I want to briefly talk about them and create JUnit 5 Extensions for measuring the time of tests in a 10 minute video.
Extension code for measuring test time [/b] import 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');
}
}
JUnit 5 homepage
Overview
10 interesting innovations
Extension Model
A Guide to JUnit 5
Migrating from JUnit 4
Before and After Test Execution Callbacks
Conditional Test Execution
Third party Extensions
Implementation of assertThat
Thank you for attention!
I hope that if your project uses JUnit 4 and you have not yet migrated to JUnit ? this little video will inspire you. And also on the use of JUnit 5 in your new projects.
It may be interesting
weber
Author22-08-2018, 05:35
Publication DateTesting of IT systems / Programming
Category- Comments: 0
- Views: 280
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
메리트카지노
Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
메리트카지노
opencart eticaret
This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
메리트카지노
Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. [Url = https: //mtsoul.net] 먹튀 검증 [/ url]