IConfigurationAnnotation not properly initialized when passing to IAnnotationTransformer2 transform() method.

105 views
Skip to first unread message

Filus

unread,
Oct 17, 2011, 7:49:33 AM10/17/11
to testng-dev
Hi,

I've wrote IAnnotationTransformer2 listener to change configuration
annotation for some circumstances, and surplisingly found out that
IConfigurationAnnotation is not properly initialized before passing to
IAnnotationTransformer2 transform method. All field are still default
- falses and nulls.

So e.g. I expect AfterTest annotation, I use
IConfigurationAnnotation.getAfterTest() method to check, but it always
returns false. Others fields, the same. I've checked TestNg versions
from 6.0 to 6.3.

*Example*:
Test class:

package pl.filus;

import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.annotations.AfterTest;

public class AnnotationDisableListenerTest {

@BeforeTest
public void beforeTest() {
System.out.println("Before Test");
}

@Test
public void testing() {
System.out.println("Testing");
}

@AfterTest
public void afterTest() {
assert false;
}
}

Listener:

package pl.filus;

import org.testng.IAnnotationTransformer2;
import org.testng.annotations.IConfigurationAnnotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.annotations.IDataProviderAnnotation;
import org.testng.annotations.IFactoryAnnotation;
import org.testng.annotations.ITestAnnotation;

public class AnnotationDisableListener implements
IAnnotationTransformer2 {
public void transform(IConfigurationAnnotation
iConfigurationAnnotation, Class aClass, Constructor constructor,
Method method) {
System.out.format("%s %s %s\r\n", method.getName(),
iConfigurationAnnotation.getBeforeTest(),
iConfigurationAnnotation.getAfterTest());

iConfigurationAnnotation.setEnabled(false); //this works.
}

public void transform(IDataProviderAnnotation
iDataProviderAnnotation, Method method) {
//Default implementation
}

public void transform(IFactoryAnnotation iFactoryAnnotation, Method
method) {
//Default implementation
}

public void transform(ITestAnnotation iTestAnnotation, Class aClass,
Constructor constructor, Method method) {
//Default implementation
}
}

testng.xml:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite">
<listeners>
<listener class-name="pl.filus.AnnotationDisableListener"/>
</listeners>
<test name="Test">
<classes>
<class name="pl.filus.AnnotationDisableListenerTest"/>
</classes>
</test>
</suite>

In result we'll see on console:

beforeTest false false
afterTest false false
Testing

But it should be:

beforeTest true false
afterTest false true
Testing

Cédric Beust ♔

unread,
Oct 19, 2011, 2:44:24 AM10/19/11
to testn...@googlegroups.com, Filus
Hi,

I just fixed this, can you try the beta and report back?


Thanks!

-- 
Cédric





--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to testn...@googlegroups.com.
To unsubscribe from this group, send email to testng-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.


Filus

unread,
Oct 19, 2011, 9:15:23 AM10/19/11
to testng-dev
On 19 Paź, 08:44, Cédric Beust ♔ <ced...@beust.com> wrote:
> I just fixed this, can you try the beta and report back?

So, I've tried this beta, made some tests and it seems to be working
okay :)

Thanks!

--
Filus
Reply all
Reply to author
Forward
0 new messages