[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] can anyone help me to take a look my exceptionhandler ?
|
hello all,
sorry re-post this article again , because my first post is not subscription
of mailing list ,so you guys can not receive my help request, and sorry for
this inconvenience .
I'm a new aspectj starter and I want to use aspectj to handle exceptions
which thrown/catched in my testcases, but seems don't work as expect...
my code like this:
1. all the testcases in package com.mycompany.myapp.qe.ui.test.xxx
all the testcases include try/catch blocker to handle the exception to take
screenshot/stack trace and so on ...
example of one testcase:
public void caseName() throw exception
{
try{
//test case scenario
}catch(Throwable t)
{
captureThrowable(t) // this method to take snapshot once
exception throw
}
}
captureThrowable function like this :
protected void captureThrowable(Throwable e)
{
try{
//take snaoshot
// take stack trace
} catch(Throwable t)
{
loginfo("xxxxx",t);
}
}
I used testng 5.14, aspectj 1.6.5 release
config of my pom file like this :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
dependency>
<groupId>org.aspectj</groupId>
<artifactId>com.springsource.org.aspectj.runtime</artifactId>
<version>1.6.5.RELEASE</version>
</dependency>
2. So I want to use aspectj to handle all the exceptions which
catched/thrown in my testcases
I did it like this :
@Aspect
public class ExceptionHandler{
@Pointcut("execution(@org.testng.annotations.Test *
com.mycompany.myapp.qe.ui.test..*.*(..)) && (!within(ExceptionHandler))")
public void exceptionHunting(JoinPoint jp) {
}
@AfterThrowing(value = "exceptionHunting(jp)", throwing = "t")
public void monitorExceptions(JoinPoint jp, Throwable t) throws
IOException
{
Signature signature = jp.getSignature();
Logger log = LoggerHelper.getLogger(signature.getDeclaringTypeName());
//some syntax for handle methodName and date format
captureScreenShot(jp, date + methodName + "Error.png"); // handle
snapshot action
captureStackTraceToErrorDir(jp, date + methodName + "Error.txt", t);
//handle stack trace action
}
private void captureScreenShot(JointPoint jp ,String fileName)
{//xxxxx}
private void captureStackTraceToErrorDir(JointPoint jp ,String
fileName, Throwable error)
{//xxxxx}
}
but it didn't work as my expect , anyone can help me ?
if a demo base on my example will be very appreciate
--
View this message in context: http://aspectj.2085585.n4.nabble.com/can-anyone-help-me-to-take-a-look-my-exceptionhandler-tp4650503.html
Sent from the AspectJ - users mailing list archive at Nabble.com.