-
Notifications
You must be signed in to change notification settings - Fork 23
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
Allow grouping of describe blocks using @Test annotations so IDEs can provide selective test running at suite level #98
Comments
@zifnab87 this is the opposite paradigm to So, grouping your tests into suites is already supported your In the about-to-be-released version, you can use Migrating all your tests to use If your tests are really behavioural, then Perhaps you could post a snippet of the sort of tests you'd like to improve and we could see how they would expressed in native |
Hi @ashleyfrieze! Thanks for the quick response! What I am trying to do is integrate it with IntelliJ so I can select and run a specific test without changing the code at all. So I was seeking a way to annotate specific describes.. As far as I know As for my tests all of them are using the rule of 3A (Arrange,Act,Assert) so I have been writing my unit tests in a way that I believe can be converted to pure BDD merging a lot of them that have exactly the same Arrange parts. So yes I see a lot of value in BDD JUnit tests! |
Well well well :) You've picked on the thing which these sorts of custom test runners can't do. You'd have the same trouble using Cucumber and all the other So your request is something like - Could there be a specialist runner for Spectrum which is compatible with selective test running in IntelliJ at suite level It kind of looks like this: @RunWith(SpectrumMagicRunner.class)
public class MyTests {
@Test
public void suite1() {
describe("one", () -> { ... });
}
@Test
public void suite2() {
describe("two", () -> {
it("has a spec", () -> { ... });
});
}
} And you'd expect that the JUnit tree, when looking at this in IntelliJ or Eclipse, might have the tree in it:
And your IDE UI would let you run @greghaskins would this be a desirable twist on |
Exactly!! I hope other people share the same view with me :) Otherwise one would have to split those suits to two separate Test Classes which already are a grouping factor of our Java tests no matter what the test paradigm :) So with that suggestion people are free to be as pure BDD as Java currently supports or be more integrated with JUnit capabilities that if are not there it could discourage the use of BDD Runners like Spectrum due to upper management objections for example. In your example above I would expect:
with the ability to have multiple describes in |
If your upper management are deciding how you unit test, you're in more trouble than a choice of test runner :) Have you considered using JUnit to group your specs? Here's a solution @RunWith(Enclosed.class) // junit native runner
public class GroupOfSpecs {
@RunWith(Spectrum.class)
public static class Group1 {{
describe("...", () -> {}); //etc
}}
@RunWith(Spectrum.class)
public static class Group2 {{
describe("...", () -> {}); //etc
}}
} Unless I'm wrong, I think you can selectively run each of the inner classes. The Does that help? |
@ashleyfrieze 's suggestion should get part of the way there @zifnab87, and it works out of the box. I've used it myself to only run a subset of tests at a time from my IDE. It may not even require the JUnit5 (#68) is probably a better long-term solution for this, since that platform provides better support for alternative test runners, whereas JUnit4 very much wants a class name and a method name (which are used both for display and filter/re-run purposes). At least IntelliJ has started on proper IDE support for JUnit5. |
Ha! Currently I am not under any management myself especially considering the technologies I've picked to work with :) What I was trying to say is that this thought would come in the majority of cases in the industry considering rewriting their tests that can be modeled with BDD.. Let me try the suggestion, although a bit hacky and see if that causes any problems I will let you know :) Does JUnit5 already support runners running parts of lambda functions? |
@greghaskins, @ashleyfrieze so I tried doing what you suggested.. Unfortunately a lot of my dependencies that are private would need to be put as public everywhere.. so all the inner classes can access those. Also I have when I try to run a class that looks like that:
it obviously ignores BDDTest if I change the outer extends to be
I can run the inner test .. but when I run all tests or the outer class I get initialization error - no runnable method found or something like that.. This approach that you suggested, unfortunately, doesn't seem to scale for real applications like mine. |
You can't expect the instance properties of the outer class to have meaning when you're using it as a suite. Each inner class would need to be a fully functioning test, and should, therefore, have its own properties and Warning - you're expecting |
I am able to make |
Which version are you using now? Support for spring will improve not reduce as we move forward. Can you provide the code from your base classes? This feels hacky now because you are trying to push native junit features into Spectrum rather than use its own approach. E.g @before vs beforeEach or let |
sure! Keep in mind that have 130+ tests currently that are integration tests due to the fact that I run against an in memory graph database instead of disk-based one.. Unfortunately graph databases are not really unit testable..Regardless they are behavior oriented and I really liked the way that the tests can be written and grouped together compared to the old approach I have still..I am running 1.0.2. Below are the two parent classes. These are the global @Autowired dependencies to minimize the initialization clutter in all of my tests, I also have @Autowired dependencies per test.. As you can guess the application is quite a bit complicated
|
Ok.... In the current code (i.e. head of master) there are two ways you could integrate Here's how you can do it in the latest version (soon to be released). Method 1Remove your constructor from Then make each of your test classes inherit Method 2Consider your test eco system as an object. It's an object you want to be used by each of your tests. So rename Then use Both of the above are the way to bridge from JUnit boilerplate to |
About Method 1: what happens when someone doesn't have any config like my case.. Spring / Spring Boot / Spring Boot Test is moving towards removing config files and going towards auto-detection of injectables based on the locaton of the SpringBootApplication |
Sorry - used wrong markup The example shown is a classic configure by config object Spring example. Don't focus on that. The |
I recommend that we close this @greghaskins as I think it goes against the nature of |
How about supporting this hybrid approach? This way there won't be too much need of fit, fdescribes etc and people will be able to use Spectrum without losing anything - Not sure if this is related to #79
If this can be done somehow I will migrate all my tests to use Spectrum!
The text was updated successfully, but these errors were encountered: