google / thread-weaver

A Java framework for testing multithreaded code.
Apache License 2.0
307 stars 62 forks source link

Failing tests cause errors instead of failures #4

Open DavidZemon opened 9 years ago

DavidZemon commented 9 years ago

I've modified the first example in a simple fashion. I'm hoping maybe you could incorporate these changes into AnnotatedTestRunner.runTests(...):

    @Test
    public void testThreading() {
        final AnnotatedTestRunner runner = new AnnotatedTestRunner();
        // Run all Weaver tests in this class, using MyList as the Class Under Test.
        try {
            runner.runTests(this.getClass(), MyList.class);
        } catch (final RuntimeException e) {
            final Throwable root = org.apache.commons.lang.exception.ExceptionUtils.ExceptionUtils.getRootCause(e);
            if (root instanceof AssertionError)
                throw (AssertionError) root;
            else
                throw e;
        }
    }
alasdairmackintosh commented 9 years ago

Thanks for the update. I am a bit busy at the moment, but will take a look in a few days.

Alasdair On 25 Feb 2015 08:15, "David Zemon" notifications@github.com wrote:

I've modified the first example in a simple fashion. I'm hoping maybe you could incorporate these changes into AnnotatedTestRunner.runTests(...):

@Test
public void testThreading() {
    final AnnotatedTestRunner runner = new AnnotatedTestRunner();
    // Run all Weaver tests in this class, using MyList as the Class Under Test.
    try {
        runner.runTests(this.getClass(), MyList.class);
    } catch (final RuntimeException e) {
        final Throwable root = ExceptionUtils.getRootCause(e);
        if (root instanceof AssertionError)
            throw (AssertionError) root;
        else
            throw e;
    }
}

— Reply to this email directly or view it on GitHub https://github.com/google/thread-weaver/issues/4.

alasdairmackintosh commented 9 years ago

On Wed, Feb 25, 2015 at 8:15 AM, David Zemon notifications@github.com wrote:

I've modified the first example in a simple fashion. I'm hoping maybe you could incorporate these changes into AnnotatedTestRunner.runTests(...):

@Test
public void testThreading() {
    final AnnotatedTestRunner runner = new AnnotatedTestRunner();
    // Run all Weaver tests in this class, using MyList as the Class Under Test.
    try {
        runner.runTests(this.getClass(), MyList.class);
    } catch (final RuntimeException e) {
        final Throwable root = ExceptionUtils.getRootCause(e);
        if (root instanceof AssertionError)
            throw (AssertionError) root;
        else
            throw e;
    }
}

Hi David,

My only slight concern about doing this is that it would drag in yet another dependency to the build, which already has a lot of dependencies. How important do you think this is?

Alasdair

DavidZemon commented 9 years ago

Definitely understandable. I'd say take a look at the source code for ExceptionUtils.getRootCause and just implement it yourself.