Skip to content
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

Closed
wants to merge 34 commits into from

Conversation

dipak-pawar
Copy link
Contributor

Changes proposed in this pull request:

  • ClassRule ArquillianTestClass
  • MethodRule ArquillianTest
  • Tests with Test lifecycle event.
  • Documentation

Fixes: #145

@bartoszmajsak
Copy link
Member

bartoszmajsak commented Dec 18, 2017

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

@bartoszmajsak
Copy link
Member

bartoszmajsak commented Dec 18, 2017

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.

Copy link
Member

@lordofthejars lordofthejars left a 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?

@dipak-pawar
Copy link
Contributor Author

@lordofthejars TestWatchman is not required for user to be added in tests. This is just an example if user has to use another MethodRule along with ArquillainTest Method Rule, then user has to make sure that ArquillianTest Rule is used as Outer Rule using RuleChain to work it correctly

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
Copy link
Member

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.

@Steve973
Copy link

Thanks for this, @dipak-pawar . It is a great addition, and with this change, it will make it easy to use Arquillian with Spock.

@dipak-pawar
Copy link
Contributor Author

@Steve973: @ahus1 is original hero of this feature. Thanks to him from my side

@smiklosovic
Copy link
Member

smiklosovic commented Dec 19, 2017

@dipak-pawar

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

@lordofthejars

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?

@bartoszmajsak
Copy link
Member

bartoszmajsak commented Dec 19, 2017

I dont know if I am just pedantic

You are not alone ;)

I am not sure why the code is kind of "squeezed" in order not to exceed 80 chars per line ..

We have IDEA and .editorconfig available here https://github.com/arquillian/org-settings/blob/master/code-settings/arquillian-idea-code-style.xml#L142. This is now set to 122 chars, but doesn't harm to make it longer we most of us use 16:9 screens these days anyway.

@bartoszmajsak
Copy link
Member

bartoszmajsak commented Dec 19, 2017

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?

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!

Copy link
Member

@bartoszmajsak bartoszmajsak left a 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.
Copy link
Member

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 and ArquillianTest - 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`.
Copy link
Member

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?

Copy link
Contributor Author

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);
}
}
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`RuleChain`

Copy link
Member

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) {
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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

Copy link
Contributor Author

@dipak-pawar dipak-pawar Dec 20, 2017

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

Copy link
Member

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.

@bartoszmajsak
Copy link
Member

Awesome work @dipak-pawar.

And kudos to @ahus1 for kicking this work off!

giphy 34

@bartoszmajsak
Copy link
Member

Upstream 6dc0cf4! Thanks!

@ahus1
Copy link
Contributor

ahus1 commented Dec 20, 2017

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants