You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-dev@maven.apache.org by Tom Nelson <to...@gmail.com> on 2010/05/12 20:19:12 UTC
Re: TestNG @BeforeMethod not working on subclasses.
Hi Dan,
I have insight on this and I think that it is a surefire bug when using
TestNG and AbstractTestNGSpringContextTests which requires subclassing and
uses @BeforeMethod, @AfterMethod,
the default generated suite file generates something like:
<test name="Command line test(failed)" junit="false" annotations="JDK">
<classes>
<class name="com.workscape.orgchartconfig.OrgChartSyncGetTest">
<methods>
<include name="springTestContextBeforeTestMethod"/>
<include name="beforeClass"/>
<include name="beforeMethod"/>
<include name="afterMethod"/>
<include name="springTestContextAfterTestMethod"/>
<include name="springTestContextPrepareTestInstance"/>
<include name="orgChartSyncGetTest"/>
</methods>
</class>
</classes>
</test>
-- it appears that annotated methods are being incorrectly treated as test
method. (I'm using 2.4.2)
By explicitly providing a suite file like:
<test name="this should work" junit="false" annotations="JDK" verbose="2">
<classes>
<class name="com.workscape.dao.DAOTest" />
</classes>
</test>
<test name="this should work 2" junit="false" annotations="JDK"
verbose="2">
<classes>
<class name="com.workscape.dao.DAONegativeTest" />
</classes>
</test>
I was able to workaround the issue.
dfabulich wrote:
>
> roadtripryan wrote:
>
>> I am trying to test using TestNG/Spring/ and Maven Surefire 2.4.1.
>>
>> My test suite runs great from within eclipse as individual tests or as a
>> whole suite. When I try and run the tests in Maven Surefire, however,
>> they
>> fail. It appears Surefire is not calling the correct @BeforeMethod
>> method.
>> (When running the whole suite, or an individual test.)
>
> As you might expect, all Surefire does is call TestNG directly; we don't
> directly call @BeforeMethod, @Test, etc.
>
>> From testing it, it seems Surefire calls the @BeforeMethod in the base
>> class, but not in extending classes if they override it. I am extending
>> Springs AbstractTestNGSpringContextTests, and it is calling the base
>> class
>> methods, not my extending classes @BeforeMethod and @AfterMethod.
>> Interestingly, it seems to call the correct @BeforeClass method.
>
> If you're having a problem with a TestNG test that you believe should be
> working, please file a bug on jira.codehaus.org; please also attach a
> minimal Maven project that reproduces the problem. Ideally a test like
> this should be nothing more than a pom.xml file and a couple of TestNG
> classes in appropriate directories. (Please don't include any spring
> classes in this test case unless it's absolutely necessary to do so.)
>
> -Dan
>
>
--
View this message in context: http://old.nabble.com/TestNG-%40BeforeMethod-not-working-on-subclasses.-tp15418799p28539411.html
Sent from the Surefire - Developer mailing list archive at Nabble.com.
Re: TestNG @BeforeMethod not working on subclasses.
Posted by Kristian Rosenvold <kr...@gmail.com>.
Den 12. mai 2010 kl. 20.19 skrev Tom Nelson <to...@gmail.com>:
>
> Hi Dan,
> I have insight on this and I think that it is a surefire bug when
> using
> TestNG and AbstractTestNGSpringContextTests which requires
> subclassing and
> uses @BeforeMethod, @AfterMethod,
> the default generated suite file generates something like:
>
> <test name="Command line test(failed)" junit="false"
> annotations="JDK">
> <classes>
> <class name="com.workscape.orgchartconfig.OrgChartSyncGetTest">
> <methods>
> <include name="springTestContextBeforeTestMethod"/>
> <include name="beforeClass"/>
> <include name="beforeMethod"/>
> <include name="afterMethod"/>
> <include name="springTestContextAfterTestMethod"/>
> <include name="springTestContextPrepareTestInstance"/>
> <include name="orgChartSyncGetTest"/>
> </methods>
> </class>
> </classes>
> </test>
>
> -- it appears that annotated methods are being incorrectly treated
> as test
> method. (I'm using 2.4.2)
> By explicitly providing a suite file like:
>
> <test name="this should work" junit="false" annotations="JDK"
> verbose="2">
> <classes>
> <class name="com.workscape.dao.DAOTest" />
> </classes>
> </test>
> <test name="this should work 2" junit="false" annotations="JDK"
> verbose="2">
> <classes>
> <class name="com.workscape.dao.DAONegativeTest" />
> </classes>
> </test>
>
> I was able to workaround the issue.
>
> dfabulich wrote:
>>
>> roadtripryan wrote:
>>
>>> I am trying to test using TestNG/Spring/ and Maven Surefire 2.4.1.
>>>
>>> My test suite runs great from within eclipse as individual tests
>>> or as a
>>> whole suite. When I try and run the tests in Maven Surefire,
>>> however,
>>> they
>>> fail. It appears Surefire is not calling the correct @BeforeMethod
>>> method.
>>> (When running the whole suite, or an individual test.)
>>
>> As you might expect, all Surefire does is call TestNG directly; we
>> don't
>> directly call @BeforeMethod, @Test, etc.
>>
>>> From testing it, it seems Surefire calls the @BeforeMethod in the
>>> base
>>> class, but not in extending classes if they override it. I am
>>> extending
>>> Springs AbstractTestNGSpringContextTests, and it is calling the base
>>> class
>>> methods, not my extending classes @BeforeMethod and @AfterMethod.
>>> Interestingly, it seems to call the correct @BeforeClass method.
>>
>> If you're having a problem with a TestNG test that you believe
>> should be
>> working, please file a bug on jira.codehaus.org; please also attach a
>> minimal Maven project that reproduces the problem. Ideally a test
>> like
>> this should be nothing more than a pom.xml file and a couple of
>> TestNG
>> classes in appropriate directories. (Please don't include any spring
>> classes in this test case unless it's absolutely necessary to do so.)
>>
>> -Dan
>>
>>
>
> --
> View this message in context: http://old.nabble.com/TestNG-%40BeforeMethod-not-working-on-subclasses.-tp15418799p28539411.html
> Sent from the Surefire - Developer mailing list archive at Nabble.com.
>