-
Notifications
You must be signed in to change notification settings - Fork 98
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
Use Spring's @Rule support instead of @RunWith(SpringJunit4ClassRunner) #250
Conversation
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.
Thank you for the PR! It would be great if you could address the comments, mainly to keep the old rule-less way, so that users of old Spring versions are still supported.
@@ -19,10 +16,16 @@ | |||
* | |||
* @since 0.8.0 | |||
*/ | |||
public class SpringScenarioTest<GIVEN, WHEN, THEN> extends | |||
ScenarioTest<GIVEN, WHEN, THEN> implements BeanFactoryAware { | |||
public class SpringScenarioTest<GIVEN, WHEN, THEN> extends InternalSpringScenarioTest<GIVEN, WHEN, THEN> { |
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 think we need to introduce a new class here, something like RuleBasedSpringScenarioTest
. Otherwise users of old Spring versions will not be able to use that class anymore.
|
||
import com.tngtech.jgiven.integration.spring.SpringScenarioTest; | ||
|
||
@RunWith( SpringJUnit4ClassRunner.class ) |
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.
Same as above: we still need to support the runner-based execution
* | ||
* @since 0.14.0 | ||
*/ | ||
public abstract class InternalSpringScenarioTest<GIVEN, WHEN, THEN> extends ScenarioTestBase<GIVEN, WHEN, THEN> implements BeanFactoryAware { |
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 the constructor is already package-private you could also make the class itself package-private
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.
No, this does not work because of Springs ClassRule:
org.junit.internal.runners.rules.ValidationError: The @ClassRule 'springClassRule' must be declared in a public class.
Would you think it's more consistent to have the constructor public then?
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.
And move it to a package named "internal"?
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.
no I think that would be overkill. The class is visible in any case, so just leave it as it is
public void setupSpring() { | ||
wireSteps( new SpringCanWire( beanFactory ) ); | ||
} | ||
@ContextConfiguration( classes = TestSpringConfig.class ) |
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.
good catch, thanks for adapting that!
I created new classes as suggested. |
Or SimpleSpringRuleScenarioTest and SpringRuleScenarioTest ? |
That is even better :-) |
…arting with version 4.2, as an alternative to SpringScenarioTest using SpringJUnit4ClassRunner. Enables the use of custom JUnit runners like DataProviderRunner.
Incorporated the changes. |
fixes #229 |
Use Spring's @rule support added in v4.2 for the SpringScenarioTest instead of using SpringJUnit4ClassRunner.
Enables the use of custom JUnit runners like DataProviderRunner (see example test).