Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] can anyone help me to take a look my exceptionhandler ?

@Alexander,
Hi sir, that's really what I want, you given me a very powerful support !
thanks again from my heart, thank you so ..... much !!!!!!!

On Fri, Aug 31, 2012 at 8:29 PM, Alexander Kriegisch-2 [via AspectJ] <[hidden email]> wrote:
Like this?

##### some JUnit 4 tests #####

package de.scrum_master.aop.demo;

import static org.junit.Assert.*;
import org.junit.Test;

public class MyTestCase {
    @Test public void testOne() {
        assertEquals("scrum-master.de", "scrum-" + "master" + ".de");
    }

    @Test public void testTwo() {
        throw new RuntimeException("Unexpected test exception");
    }

    @Test public void testThree() {
        fail("Not yet implemented");
    }

    @Test public void testFour() {
        throw new RuntimeException("Another unexpected test exception");
    }
}

##### an aspect taking care of exception logging #####

package de.scrum_master.aop.demo;

import org.junit.Test;

public aspect TestExceptionHandler {
    protected void captureThrowable(Throwable t) {
        System.err.println(t);
    }

    after() throwing (Throwable t) : execution(@Test * *(..)) {
        captureThrowable(t);
    }
}

I am not catching the exceptions, just logging them, so as to make your
tests fail as expected for unexpected exceptions. The output looks like
this:

> java.lang.RuntimeException: Unexpected test exception
> java.lang.AssertionError: Not yet implemented
> java.lang.RuntimeException: Another unexpected test exception



xianglong, <a href="" value="+13108201208" target="_blank">31.08.2012 08:49:

> @Alexander option c is my concern
>
>> Yes, I think I can help you if you tell me (in prose, not in code)

>> what you want to achieve: Do you want to
>>
>> a) intercept and log the exceptions in your production code, then
>> pass them through (i.e. let them happen)?
>>
>> b) intercept and log the exceptions in your production code, but
>> *not* pass them through (i.e. catch them)?
>>
>> c) just avoid code duplication with try/catch blocks in your test
>> cases?
>>
>> d) anything else?
_______________________________________________
aspectj-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/aspectj-users



If you reply to this email, your message will be added to the discussion below:
http://aspectj.2085585.n4.nabble.com/can-anyone-help-me-to-take-a-look-my-exceptionhandler-tp4650503p4650510.html
To unsubscribe from can anyone help me to take a look my exceptionhandler ?, click here.
NAML



View this message in context: Re: can anyone help me to take a look my exceptionhandler ?
Sent from the AspectJ - users mailing list archive at Nabble.com.

Back to the top