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

cucumber-spring should use TestContextManager #448

Closed
aslakhellesoy opened this issue Jan 13, 2013 · 4 comments
Closed

cucumber-spring should use TestContextManager #448

aslakhellesoy opened this issue Jan 13, 2013 · 4 comments

Comments

@aslakhellesoy
Copy link
Contributor

Spring's JUnit and TestNG runners use org.springframework.test.context.TestContextManager internally. This class is available in org.springframework:spring-test:3.2.0.RELEASE.

I think that using this internally somewhere in cucumber.runtime.java.spring would make it easier to fix #438 and possibly simplify/improve the cucumber-spring module as well.

I'm not familiar enough with Spring to implement this, so it would be great to get some help from previous cucumber-spring contributors. /cc @ffbit @vladimirkl @paoloambrosio @andrena @ovstetun

@pasviegas
Copy link
Contributor

I know its not perfect, but something like this on the SpringFactory should work. Actually it is close to what SpringJunit4ClassRunner does.

public <T> T getInstance(final Class<T> type) {
        try {
            T instance = createTest(type);
            TestContextManager contextManager = new TestContextManager(type);
            contextManager.prepareTestInstance(instance);
            return instance;
        } catch (Exception exception) {
            throw new CucumberException(exception.getMessage(), exception);
        }
    }

    @SuppressWarnings("unchecked")
    protected <T> T createTest(Class<T> type) throws Exception {
        return (T) type.getConstructors()[0].newInstance();
    }

@aslakhellesoy
Copy link
Contributor Author

Would you be interested in sending a pull request for this with some tests?

@pasviegas
Copy link
Contributor

Sure, I'll send it this week! =)

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants