Comments (10)
@ekovacs the central request appears to be having rules on a Suite propagate to the children.
We don't have plans to do propagation, and I don't know how that would be implemented.
Also we generally avoid features where you get different behavior in a test depending on how it was run. IDEs and even some build tools let you run individual test cases or methods. When running a test in isolation, how does it know that it should inherit behavior from a parent suite?
Perhaps the JUnit 5 test engine abstraction is a better solution for some of the larger problems mentioned in the comments on this Issue.
from junit4.
While we're at it, how about for the up and coming Categories? I can see having code that should run before and after all tests belonging to a specific Category, or before/after a single test that belongs to that Category.
from junit4.
To run a rule before and after each single Category test (or before/after a test with any kind of annotation) wouldn't be a problem. Just make a rule that matches annotations. A base class for this could easily be provided by the JUnit framework.
To make a rule that runs before the first test of many in a category wouldn't be a problem either. Just make a rule that looks for Category and then runs once before the first test it finds.
To run a rule after all the tests of a specific category can be more tricky depending on the requirements. It could be solved by having e.g. the same rule instance that ran before the tests run at the very end iff there were any categories in the suite.
To make a rule run after the last test in a category, but before the next test, that would require some more thought, though. One way would be to allow a visitor to traverse the test structure after it has been read, but before it has been executed, and allow that visitor to add befores/afters in the execution tree.
Or there is a better solution that I totally missed...
from junit4.
I should say that this requires the Propagate feature, which allows you to declare test/test class/suite rules on any upper level, and that then propagates the rules to the sub suites and its test cases and tests.
from junit4.
Has anything happened about Rule propagation in the last 7 months?
I would love to use this feature for my ContiPerf library, which provides JUnitPerf-like features on an annotation base. I would like to be able to let the user wrap ContiPerf-agnostic JUnit tests with a test suite that acts as a 'Decorator' and adds special invocation behaviour to each test method, ideally independently of the called classes' own Runner.
After recognizing that there is no way to propagate a Rule in a suite, I wrote a custom Runner using @RunWith, which works fine when applied as the only Runner. But when nesting Runners, it fails. An example is a test class which uses the Parameterized runner and you wrap it with a test suite with a custom runner: JUnit's AllDefaultPossibilitiesBuilder does not know the custom runner and with any further runnerForClass() invocation it is lost.
I think the best solution would be if the JUnit framework supported propagation of Rules over suites or, better, any nested RunnerBuilder invocation.
What is your opinon on this? Did I miss some other concept that could help me out? What are your current plans on Rule propagation support?
from junit4.
I'm sorry this request has lingered. Is there anyone still on the thread still interested in helping to design a solution?
from junit4.
It would be nice to have something like @ClassRule
, which wraps the whole suite.
from junit4.
@panchenko, that already exists. It's called @ClassRule
. :-) Or do I misunderstand?
from junit4.
@dsaff You are right, I missed it as my Eclipse was shipped with junit 4.8, time to upgrade :-)
from junit4.
@vbergmann would the @ClassRule solve the problem you were facing?
from junit4.
Related Issues (20)
- SpringBoot test failure in circleci HOT 3
- Confusing problem... get differernt result between `main method` and `test method` HOT 7
- Compilation error in org.junit.runner.Result - ObjectInputStream.GetField.get(name, object) throws ClassNotFoundException
- Update to hamcrest 2.2 HOT 16
- Test case grouping - Run subset of test cases depending on specific environment variables HOT 8
- Thread context classloader not reset between tests HOT 1
- Cross site scripting HOT 1
- How to test Redis Time out exception for @Cacheable method with Junit+ Spring integration test HOT 3
- Make Assert failNotEquals public HOT 1
- Assert error messages are not clear HOT 2
- Exception handling of suite() method breaks Jenkins JUnit test history reporting HOT 6
- Add support for "dynamic" default runner selection via system property HOT 8
- When will a new version of junit be released? HOT 1
- JUnitCore could not invoke test HOT 1
- Strange links on "Download and Install" page HOT 1
- junit-4.13.2 compilation error with java 21 HOT 4
- Treat org.opentest4j.TestAbortedException the same as AssumptionViolatedException HOT 4
- Which junit version supports Java 17 ? HOT 2
- Assert check not consistent HOT 9
- Receiving excessively long build DEBUG logs after updating maven-surefire-plugin from 2.22.2 to 3.3.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from junit4.