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

ErrorCollector is not working for me - can it run using Cucumber Runner class? #983

Closed
JasonSmiley opened this issue Sep 4, 2014 · 20 comments

Comments

@JasonSmiley
Copy link

ErrorCollector doesn't seem to work, even when I do the most basic test.

See code:

@Rule
public ErrorCollector test = new ErrorCollector();

@When("I test my code")
public void I_test_my_code(){
    //Sandbox step - put code here you want to test
    //new TestCase("Testing Error Handler 1", false, equalTo(true), false).runTest();
    //new TestCase("Testing Error Handler 2", false, equalTo(true), false).runTest();
    //new TestCase("Testing Error Handler 3", true, equalTo(true), false).runTest();

    test.checkThat("Testing Error Handler 1", false, equalTo(true));
    test.checkThat("Testing Error Handler 2", false, equalTo(true));
    test.checkThat("Testing Error Handler 3", true, equalTo(true));
}

Note, I am using Cucumber JVM to run my tests.

@JasonSmiley
Copy link
Author

@smoke-tests @finished @test-rerun
Feature: Testing work

@test-my-code @test
Scenario: test code
When I test my code

@JasonSmiley
Copy link
Author

I just discovered that @aslakhellesoy says this is not supported back in 2013, (https://groups.google.com/forum/#!msg/cukes/qMwgAVzWmR0/GSkRUgJ8f4EJ) can we get a "Run Rule Check" like method so I can manually call the step that JUnit calls in my @after step?

@UrsMetz
Copy link
Contributor

UrsMetz commented Sep 4, 2014

You can call ErrorCollector#verify in a method annotated with @After, that is actually what the rule is doing itself.

@JasonSmiley
Copy link
Author

Verify is protected, I cannot call from my After step directly.

@marcphilipp
Copy link
Member

I don't think this is a JUnit issue. There is a closed one over at cucumber-jvm: cucumber/cucumber-jvm#393.

@JasonSmiley
Copy link
Author

I may need to close this thread since its already off topic....

But, just to clarify, while I initially thought this was a bug in Junit. Its actually a Design Decision in Cucumber JVM at the moment. I stand corrected on that point.

However, since cucumber isn't doing this for me, I would like to execute the ErrorCollector verify function myself in Cucumber.After step.

I am not saying that Verify should be public instead of protected, however, this would solve my issue and allow me to work around this design decision.

@marcphilipp
Copy link
Member

Well, for now you could create a subclass of ErrorCollector, override verify and make it public.

@JasonSmiley
Copy link
Author

For some reason that didn't work, but, I just basically copy and pasted your files into my project.

I must have done something wrong but at least now I have more control over whats happening :)

@marcphilipp
Copy link
Member

Would it help you if we made verify public in a future release?

@kcooney
Copy link
Member

kcooney commented Sep 5, 2014

Did someone ever send a pull request to Cucumber to add Rule support? They
seemed open to the idea?
On Sep 4, 2014 9:54 PM, "Marc Philipp" [email protected] wrote:

Would it help you if we made verify public in a future release?


Reply to this email directly or view it on GitHub
#983 (comment).

@JasonSmiley
Copy link
Author

@kcooney - cucumber/cucumber-jvm#771 (comment)

I think they are open to it now :)

I was going to take a peek at this over the weekend, but if you want to take a stab I say go for it!

Edit: Updated comment reference

@kcooney
Copy link
Member

kcooney commented Sep 5, 2014

@JasonSmiley sadly I don't have time to contribute to yet another open source project, but I would be happy to help review the changes when you think they are ready

@JasonSmiley
Copy link
Author

I'll take a stab and let you know.

@marcphilipp
Copy link
Member

I'm closing this issue for now. Feel free to add a comment or refernce it from your cucumber-jvm pull request.

@JasonSmiley
Copy link
Author

Before I do anything, can someone point me in the right direction in terms of what JUnit code i should look at to see how Rules are being checked? I figure the cucumber runner will need something similar.

Just figured I would ask :)

@UrsMetz
Copy link
Contributor

UrsMetz commented Sep 5, 2014

I'm sorry my comment wasn't that helpful @JasonSmiley, I didn't notice that verify() wasn't public. But hopefully now I can be more helpful :-):
I think the important part is in org.junit.runners.BlockJUnit4ClassRunner#methodBlock() where the statement is enriched by the method withRules().

Edit: Looking at how other library (namely Spring and Mockito) implement their runners (which are compatible with Rules) I think custom runners don't have to handle Rules themselves: One has to plugin into the protected methods like withBefores or withAfters.
But they are deprecated and their JavaDocs suggest to use Rules instead.

@sarpk
Copy link

sarpk commented Nov 16, 2015

Please make verify public. I am having the same issue and running it with testng.

@kcooney
Copy link
Member

kcooney commented Nov 16, 2015

@sarpk are you using cucumber? If so, I suggest commenting on the cucumber bug. If not, can you provide a simple reproducible test case?

@sarpk
Copy link

sarpk commented Nov 16, 2015

@kcooney no I am using testng not cucumber. testng already has soft asserts which works exactly like that (where you call it's verify method when you want to)

@kcooney
Copy link
Member

kcooney commented Nov 16, 2015

@sarpk sorry, you said that in your post, and I misread it.

Users that use JUnit shouldn't need to call verify(). It is ultimately Marc's ca, but personally I would rather not make a method public that shouldn't be called by end users. I suggest asking on the TestNG forums if they have something like ErrorCollector. Alternatively, migrate your tests to JUnit :-)

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

No branches or pull requests

5 participants