Ksu
Ksu

Reputation: 83

Allure: How to rerun all Broken Tests and then generate report

I have about 150 tests. When I run them all I always have about 2-5% of broken tests, and there are always different tests...

What I want: Run tests once, and if there were broken tests maven reruns them and then I can re-generate report with changes:it would be only Passed and Failed tests

Is it possible? What should I start from?

I use Java+Maven+JUnit)

Upvotes: 2

Views: 4621

Answers (2)

Paresh
Paresh

Reputation: 1158

If you want to clean duplicate tests after re-run from Allure report then you can refer to this repo - still in progress but basic functionality is working fine. For now it cleans duplicate tests which are generated by TesnNG + Allure!!

https://github.com/Esprizzle/allure-report-processor

Upvotes: 0

Dmitry Baev
Dmitry Baev

Reputation: 2743

Allure doesn't run your tests, it is only display the test results. So you have few options to rerun your failed tests:

  • Use rerunFailingTestsCount option from maven surefire plugin. If this option set surefire will rerun failing tests immediately after they fail. See docs for more details.

  • Use custom jUnit retry rule in your flaky tests:

    public class RetryRule implements TestRule {
    
        private int attempts;
        private int delay;
        private TimeUnit timeUnit;
    
        public RetryRule(int attempts, int delay, TimeUnit timeUnit) {
            this.attempts = attempts;
            this.delay = delay;
            this.timeUnit = timeUnit;
        }
    
        @Override
        public Statement apply(final Statement base, final Description description) {
            return new Statement() {
                @Override
                public void evaluate() throws Throwable {
                    Throwable e = null;
                    for (int i = 0; i <= attempts; i++) {
                        try {
                            base.evaluate();
                            return;
                        } catch (Throwable t) {
                            Thread.sleep(timeUnit.toMillis(delay));
                        }
                    }
                    throw e;
                }
            };
        }
    }
    

    And add it to each flaky test:

    @Rule
    public RetryRule retryRule = new RetryRule(2, 1, TimeUnit.SECONDS);
    

    You can find more information about jUnit rules here.

Upvotes: 3

Related Questions