Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

o.t.internal.Utils recognizes all @After* annotations as @AfterMethod #126

Closed
lukasj opened this issue Nov 5, 2011 · 2 comments
Closed

Comments

@lukasj
Copy link
Contributor

lukasj commented Nov 5, 2011

-pass following listener to TestNG (6.4/beta):

package tnl;
import org.testng.*;
import org.testng.internal.Utils;

public class Tnl2 implements IConfigurationListener {

    public void onConfigurationSuccess(ITestResult itr) {
        System.out.println(Utils.detailedMethodName(itr.getMethod(), true));
    }

    public void onConfigurationFailure(ITestResult itr) {
    }

    public void onConfigurationSkip(ITestResult itr) {
    }
}

-and run following test:

package test;
import org.testng.annotations.*;

public class StTest {

    @Test
    public void y() {
        //empty
    }

    @AfterMethod
    public void afterMethod() {
        System.out.println("AM");
    }

    @AfterSuite
    public void afterSuite() {
        System.out.println("AS");
    }

    @AfterGroups
    public void afterGroups() {
        System.out.println("AG");
    }

    @AfterClass
    public void afterClass() {
        System.out.println("AC");
    }
}

=> listener reports:

[TestNG] Running:
  Ant suite

AM
@AfterMethod StTest.afterMethod()[pri:0, instance:test.StTest@475b73eb]
AC
@AfterMethod StTest.afterClass()[pri:0, instance:test.StTest@475b73eb]
AS
@AfterMethod StTest.afterSuite()[pri:0, instance:test.StTest@475b73eb]

===============================================
Ant suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Bit of debugging on my end showed that inner state of an instance of ITestNGMethod returned by ITestResult.getMethod() (where ITestResult is passed to listener.onConfigurationSuccess() by testng internals) looks strange:

-added following snippet to o.t.reporters.TextReporter:

    @Override
    public void onConfigurationSuccess(ITestResult tr) {
        System.out.println(Utils.detailedMethodName(tr.getMethod(), true));
        ITestNGMethod m = tr.getMethod();
        System.out.print(m.isBeforeMethodConfiguration() + " (BM) + ");
        System.out.print(m.isBeforeClassConfiguration() + " (BC) + ");
        System.out.print(m.isBeforeTestConfiguration()+ " (BT) + ");
        System.out.print(m.isBeforeGroupsConfiguration() + " (BG) + ");
        System.out.println(m.isBeforeSuiteConfiguration() + " (BS)");
        System.out.print(m.isAfterMethodConfiguration() + " (AM) + ");
        System.out.print(m.isAfterClassConfiguration() + " (AC) + ");
        System.out.print(m.isAfterTestConfiguration() + " (AT) + ");
        System.out.print(m.isAfterGroupsConfiguration() + " (AG) + ");
        System.out.println(m.isAfterSuiteConfiguration() + " (AS)");
}

shown in the test output:

[TestNG] Running:
  Ant suite

PASSED: StTest.y()[pri:0, instance:test.StTest@2253d4bf]
AM
@AfterMethod StTest.afterMethod()[pri:0, instance:test.StTest@2253d4bf]
false (BM) + false (BC) + false (BT) + false (BG) + false (BS)
true (AM) + true (AC) + true (AT) + false (AG) + true (AS)
AC
@AfterMethod StTest.afterClass()[pri:0, instance:test.StTest@2253d4bf]
false (BM) + false (BC) + false (BT) + false (BG) + false (BS)
true (AM) + true (AC) + true (AT) + false (AG) + true (AS)
...
AS
@AfterMethod StTest.afterSuite()[pri:0, instance:test.StTest@2253d4bf]
false (BM) + false (BC) + false (BT) + false (BG) + false (BS)
true (AM) + true (AC) + true (AT) + false (AG) + true (AS)

Since I don't now much about internals I'm afraid that if I try to fix this (somewhere in o.t.internal.ConfigurationMethod.createAfterConfigurationMethods() ?) I'll break some other, more important functionality, so I can possibly get around this by using ITestNGMethod.getMethod().getAnnotation() for now

@cbeust
Copy link
Collaborator

cbeust commented Nov 8, 2011

You were right, it was a silly bug :-)

I just fixed it and pushed the change, can you pull and verify?

Thanks!

@cbeust cbeust closed this as completed Nov 8, 2011
@lukasj
Copy link
Contributor Author

lukasj commented Nov 10, 2011

Pulled, tried, verified => works as expected now, thanks for prompt fixing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants