junit-insights | Extension JUnit which provides insights | Application Framework library
kandi X-RAY | junit-insights Summary
kandi X-RAY | junit-insights Summary
JUnit Insights is an extension for JUnit 5 (optionally in combination with the Spring framework), which. Background: When building integration tests with Spring (e.g. with @SpringBootTest), sometimes a Spring application context has to be started and sometimes it doesn't. For the user of the test classes, it looks like some tests take a long time to execute, although the actual test runs fairly quickly. To make this behavior transparent, a report is created. If you want to learn more about when a new Application Context is created, have a look at this article explaining the topic.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of junit-insights
junit-insights Key Features
junit-insights Examples and Code Snippets
Community Discussions
Trending Discussions on junit-insights
QUESTION
Background:
My goal is to collect various timestamps while executing JUnit 5 tests in a Spring environment to create a statistic of the durations of the different tasks. (Repository for reference)
Because I can't touch the actual test code, I have to register callbacks like the ContextRefreshedEvent from within my JUnit Jupiter extension. Currently I am registering these callbacks in a Spring configuration object and hope that this is found by some component scan in the test application. As you can imagine this does not work reliably for every test context.
Problem:
I hope that I can somehow register these events like the ContextRefreshedEvent manually in my first callback method from JUnit. As far as I understand, this requires me to add either a Configuration or a Component containing the callbacks to the currently running Spring Context at runtime.
Is that possible or do you know any other solution to my initial problem? I would really appreciate any input you have on this issue because I am working on this for quite a while now.
Thank you very much in advance!
...ANSWER
Answered 2019-Mar-28 at 11:40Update:
Spring Framework 5.2 will have built-in support for test events. See GitHub issue 18490 for details.
The best way to fire test-related events in a Spring ApplicationContext
is to implement a custom (Spring) TestExecutionListener
that fires the events via the ApplicationEventPublisher
API (which ApplicationContext
implements).
You can access the test's ApplicationContext
within lifecycle methods in your custom TestExecutionListener
via TestContext#getApplicationContext()
.
To avoid having to touch test code, you can have Spring automatically register your custom TestExecutionListener
, as described here: https://docs.spring.io/spring/docs/5.1.4.RELEASE/spring-framework-reference/testing.html#testcontext-tel-config-automatic-discovery
Your custom TestExecutionListener
will then be automatically applied to all tests run via the Spring TestContext Framework -- unless a given test class is configured to override the default listeners (e.g., via @TestExecutionListeners(...)
).
For related discussion, see the following Spring JIRA issues:
Regards,
Sam (author of the Spring TestContext Framework)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install junit-insights
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page