Coder Social home page Coder Social logo

Comments (10)

kcooney avatar kcooney commented on July 21, 2024 2

@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.

aisrael avatar aisrael commented on July 21, 2024

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.

brolund avatar brolund commented on July 21, 2024

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.

brolund avatar brolund commented on July 21, 2024

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.

vbergmann avatar vbergmann commented on July 21, 2024

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.

dsaff avatar dsaff commented on July 21, 2024

I'm sorry this request has lingered. Is there anyone still on the thread still interested in helping to design a solution?

from junit4.

panchenko avatar panchenko commented on July 21, 2024

It would be nice to have something like @ClassRule, which wraps the whole suite.

from junit4.

dsaff avatar dsaff commented on July 21, 2024

@panchenko, that already exists. It's called @ClassRule. :-) Or do I misunderstand?

from junit4.

panchenko avatar panchenko commented on July 21, 2024

@dsaff You are right, I missed it as my Eclipse was shipped with junit 4.8, time to upgrade :-)

from junit4.

ekovacs avatar ekovacs commented on July 21, 2024

@vbergmann would the @ClassRule solve the problem you were facing?

from junit4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.