-
Notifications
You must be signed in to change notification settings - Fork 195
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
Provides Arquillian As Junit Rule to use it with other runner #147
Conversation
…classrule and a rule
Adds validation for both ArquillianRule & ArquillianRunner to use at the same time
Thanks @dipak-pawar! Did you try to adjust some tests we have e.g. in Drone, Graphene or some of the showcases to see if there are any challenges? Another option would be to have it added to Chameleon as a version of SimpleDeploymentTestCase - but this time with rules instead. This will also require adjusting profiles in maven to execute both old and new test case |
I just checked on chameleon project and it works for such a simple deployment. You can see my changes here. Awesome! What I would suggest doing next is to find some more sophisticated tests in arquillian-showcase and use those rules instead - somewhat an exploratory testing round. In the meantime, I will review the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really happy with all the changes and I don't see anything wrong, just one thing from the point of view of UX, do you think it should be better/possible to simplify:
@Rule
public ArquillianTest arquillianTest = new ArquillianTest();
@Rule
public MethodRule testWatchman = MethodRuleChain.outer(arquillianTest).around(new TestWatchman());
into single @Rule
so user does not need to set both?
@lordofthejars |
docs/rules.adoc
Outdated
|
||
IMPORTANT: | ||
However while using above Junit Rules you can't inject method scoped arquillian resources. | ||
In order to use any Method Rule with `ArquillianTest` Rule, you have to use it with RuleChain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe I should change In order to use any Method Rule to In order to use any other JUnit Method Rule I know it is normal but in my case, if I had read the whole information then I had understood better.
Also, I recommend to not put the MethodRuleChain
example in the main example, just put it this part just after IMPORTANT thing, if not maybe user will copy paste it when it is not required.
Thanks for this, @dipak-pawar . It is a great addition, and with this change, it will make it easy to use Arquillian with Spock. |
Good job! I am starting to wonder what usecase I will use this for (not saying it does not have its usage, I am just excited where to try this out first haha) Could you give more love to the code formatting? I dont know if I am just pedantic but it does not read like that proverbial wine, at least for me ... I am not sure why the code is kind of "squeezed" in order not to exceed 80 chars per line ... Anyway, would it be possible to run Cube with this without Arquillian runner? Could I have some Spring test with this rule and Cube containers would be started under the hood? |
You are not alone ;)
We have IDEA and |
That was the whole idea behind this feature. I guess this is what you are looking for https://github.com/arquillian/arquillian-cube/pull/913/files#diff-aa0602ab39541b61bdbc68c44cd18b90R12 @smiklosovic if you can spend some time doing a code review as well that would be more than awesome :) But no pressure. Happy to see you around! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @ahus1 @dipak-pawar! I have few things I would like you to consider before we hit upstream.
docs/rules.adoc
Outdated
=== Rules | ||
:icons: font | ||
|
||
If you want to use arquillian functionality with some other runner. You can use Arquillian with Junit Rule using `ArquillianTestClass` and `ArquillianTest` Rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
If you want to use Arquillian Testing Platform with other JUnit Runner, you can now use JUnit Rules -
ArquillianTestClass
andArquillianTest
- and happily let Arquillian do the heavy lifting for your tests.
docs/rules.adoc
Outdated
If you want to use arquillian functionality with some other runner. You can use Arquillian with Junit Rule using `ArquillianTestClass` and `ArquillianTest` Rules. | ||
|
||
In order to use full functionality of Arquillian you have to use both the rules i.e. `ArquillianTestClass` and | ||
`ArquillianTest`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I only use one? Shouldn't we require having both to have similar functionality to what the @RunWith(Arquillian.class)
has to offer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I will update comment
docs/rules.adoc
Outdated
{ | ||
Assert.assertNotNull(arquillianTest); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use some more realistic test and new code formatting too. This test just shows then new ArquillianTest()
works ;)
docs/rules.adoc
Outdated
---- | ||
|
||
IMPORTANT: | ||
However while using above Junit Rules you can't inject method scoped arquillian resources. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to use Arquillian
upper-case in all the cases.
docs/rules.adoc
Outdated
|
||
IMPORTANT: | ||
However while using above Junit Rules you can't inject method scoped arquillian resources. | ||
In order to use any other JUnit Method Rule with `ArquillianTest` Rule, you have to use it with RuleChain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`RuleChain`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also worth to mention that unfortunately it is not possible to have one rule acting as both test class and test method rule junit-team/junit4#351 (comment)
@@ -88,6 +89,15 @@ static void runnerStarted() { | |||
lastCreatedRunner.set(lastCreatedRunner.get() + 1); | |||
} | |||
|
|||
static boolean hasAnyArquillianRule(org.junit.runners.model.TestClass testClass) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented above - maybe we should always check if both are present to fail if not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not possible to check it. I will update the documentation with limitation
@@ -0,0 +1,70 @@ | |||
/* | |||
* JBoss, Home of Professional Open Source | |||
* Copyright 2009, Red Hat Middleware LLC, and individual contributors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the year for all those classes if we stick to have it here?
import static org.jboss.arquillian.junit.JUnitTestBaseClass.wasCalled; | ||
|
||
/* | ||
* Predefined TestClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what those comments are bringing to the overall code understanding - let's remove them from all those tests.
|
||
@Rule | ||
public ArquillianTest arquillianTest = new ArquillianTest(); | ||
@Rule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting
import org.junit.runners.model.FrameworkMethod; | ||
import org.junit.runners.model.Statement; | ||
|
||
public class MethodRuleChain implements MethodRule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we simply use RuleChain
here? I'm not sure why we need this class. Especially that the way how we use it will result in calling our rule twice as it's part of the test and only then added to this rule chain (and they evaluated again).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently ArquillianTest
implements MethodRule
. While RuleChain
needs parameter of type TestRule
. So we can't simply use RuleChain
here. I will update the tests how should we use it as outer rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's expose it as a regular class so other users can leverage it too and add helpful JavaDoc to it.
This reverts commit ad1d4a6.
adds javadoc
Awesome work @dipak-pawar. And kudos to @ahus1 for kicking this work off! |
Upstream 6dc0cf4! Thanks! |
Thanks @dipak-pawar - kudos for taking this from a poof-of-concept to a shiny and documented feature! I'm buried in other work - I'm sorry that I wasn't able to participate in the tests and discussions! |
Changes proposed in this pull request:
ArquillianTestClass
ArquillianTest
Fixes: #145