-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Give suites access to test objects #189
Comments
One simple option would be to use a Rule (specifically ExternalResource), which accesses gets stuff from a public static method in the Suite. This would set up the server if it's not already done. Then, in the AfterClass in the Suite, you'd do the teardown. For more information, see my answer to How can I run different junit test based on the same (but changing) information/setup (http://stackoverflow.com/questions/8007284/how-can-i-run-different-junit-test-based-on-the-same-but-changing-information/8007983#8007983) on Stackoverflow. |
Hi guys, i think you are talking about the feature i proposed in #308. Is it what you are looking for? T |
@dsaff |
1 similar comment
@dsaff |
@Tibor17, not in general. I think this is a place to move very carefully, because if the same mutable object gets injected into multiple child tests, there's the danger that test B fails due to a mutation made by test A. I almost believe that it's better to encourage people who want to use what is essentially static state to do so using static state, since most Java developers have good intuition about how that works. |
@dsaff Regarding the mutability, we are not going to inject runner instance nor the test-class instance. The injected obj is just pure custom obj. Other frameworks with IoC do not need to care if it's mutable or not. I do not want to imaging how if it is generic type or java.lang.Object. The custom obj then should be provided into child via constructor in ParentRunner or by adding setter method there. If we decide to implement such feature and then you @dsaff are idle as usually when you do not like some pressure from the community and discard the pull request, then it will waste our time on both sides. |
Did you post a link to your public repository with a solution like you mentioned above? |
@dsaff |
I'm currently working with a legacy test suite which has a very costly setup and teardown. It's old code which uses an extension of TestSetup to start and stop the server. It overrides setUp() to start the server and then loop through each class in the suite and inject references to server objects into them.
I'm trying to work out how to do this using the new @suite and @Suite.Class annotations. I've searched the web and read a lot of stuff on @rule and MethodRules. I cannot see how to do it. There doesn't appear to be any way that stuff setup in a @BeforeClass in a @suite annotated class can be passed/injected into the tests being run.
Another thought was to create an extension of Suite and override one or more methods. But I could see how to get information from the @BeforeClass method of the class annotated with @suite into each suite class after it is instantiated.
The text was updated successfully, but these errors were encountered: