running groups of classes which inherit test methods from a base class

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

running groups of classes which inherit test methods from a base class

P. Hill-2
I created a base class which contained an elaborate data provider and a
series of (integration) tests which depend on being run in order.   I
want to reuse the base class, because the only difference between two
sets of runs
can be provided by a (gang of 4) factory method used within the test.  
See Base class below which is the base class for two test classes Var1
and Var2.  I can create two suites each referring specifically to the
classes Var1 and Var2 explicitly; This is great.

My only challenge is that I'd like to come up with a way to use groups
to find Var1 or Var2 (group1 or group2, but never both), but as soon as
I do that I can not see a way to group the test methods in the base
(testSomeStuff below), so that only one of Var1 or Var2 is run in a
suite depending on the groups I specify.

If I label tests in Base WITHOUT any groups, then they are never run
because they are not in the right group.

If I label tests in Base with ALL possible groups (group1, group2) then
ALL POSSIBLE SUBCLASSES are run, even though the sub classes are not in
the right group, but the tests are.

If I use an exclude of the group1 when running group2 in the suite, I'm
back to where I was when I specified no groups in the Base class,
because all the Base tests are now excluded.

I did consider one alternative, overriding the Base test method in the
subclasses, but this would not allow me to accomplish my original intent
to re-use everything about test, including the dataprovider, it's
dependsOnMethod, run awaysRun tag or any other annotations which are
appropriate.

Are run groups not compatible with reusing a test method and it's
annotations from a baseclass?
Am I missing some other solution?

-Paul

p.s. If the above isn't clear I can also paste in example Var1 and Var2
classes.  The only thing to note is that Var2 contains other tests to
run which are not defined in the Base.

public abstract class Base {

     @DataProvider(name = "stuffer")
     public Object[][] provideStuff() {
         String commonButComplexStuff = "common stuff";
         return new Object[][] { { commonButComplexStuff,
getSpecialStuff() } };
     }

     @Test()
     public void sanityCheck() {
         System.out.println("Sanity Check");
     }

     @Test(dataProvider = "stuffer", dependsOnMethods = "sanityCheck",
alwaysRun = true)
     public void testSomeStuff(String stuff) {
         System.out.println("Testing using " + stuff + " and " +
getSpecialStuff());
     }

     abstract protected String getSpecialStuff();
}

-Paul

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

Reply | Threaded
Open this post in threaded view
|

factory simple example

Kevin Simonson
Could somebody give me a simple example of how I would use a TestNG factory?

Kevin Simonson


 NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


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

Reply | Threaded
Open this post in threaded view
|

Re: factory simple example

Krishnan Mahadevan
Here's a simple example of how to use TestNG Factories


package newPackage;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;

public class AFactoryThatProduces {
    private String text = null;

    public AFactoryThatProduces(String text) {
        this.text = text;
    }

    @BeforeClass
    public void iAmBeforeClass() {
        System.out.println("Before class was invoked");
    }

    @Test
    public void iAmATestMethod() {
        System.out.println("I am a test method and text was " + text);
    }

    @AfterClass
    public void iAmAfterClass() {
        System.out.println("I am an after class method");
    }

    @Factory
    public static Object[] getInstance() {
        return new Object[] { new AFactoryThatProduces("TestNG"), new AFactoryThatProduces("Selenium") };
    }

}



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



On Tue, Oct 4, 2011 at 4:53 AM, Kevin Simonson <[hidden email]> wrote:
Could somebody give me a simple example of how I would use a TestNG factory?

Kevin Simonson


 NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


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


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

limitations on dependsOnMethods?

Kevin Simonson

I have a test method <updateCollection()> in my group “middle-phase” that has to be run after another test <getCollectionSummary(), also in group “middle-phase”, so <updateCollection()> looks like this:

 

@Test( dataProvider = “updColParms”, groups = { “middle-phase” }, dependsOnMethods = { “getCollectionSummary” })

public void updateCollection (    Collection original

                             , Collection… revisions)

                             Throws CdsAcceptanceException {

 

    original.setDbId( 0L);

    verifyUpdate( original, “created as”);

etc.

 

This compiles just fine, but when I go to run it my IntelliJ Console window says:

 

“C:\Program Files\Java\jdk1.6.0_23\bin\java” –agentlib:jdwp=transport=dt_socket,address=127.0.0.1:49914,suspend=y,server=n –ea –javaagent:C:\Users\kvnsmnsn\.IntelliJIdea10\system\groovyHotSwap\gragent.jar –Dfile.encoding=UTF-8 –classpath “C:\Program Fi …

Connected to the target VM, address: ‘127.0.0.1:49914’, transport: ‘socket’

org.testng.TestNGException:

org.familysearch.cds.acceptance.CollectionEndpointTest.updateCollection() is not allowed to depend on public void org.familysearch.cds.acceptance.CollectionEndpointTest.getCollectionSummary(java.lang.String,java.lang.String,java.lang.Integer) throws org.familysearch.cds.acceptance.client.CdsAcceptanceException

    at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:95)

    at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:244)

    at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:315)

Etc.

 

 

Anybody have any idea what this message means?  Are there limitations on which test methods can depend on which other test methods that is keeping me from getting this one method to depend on the other?  If so, what are those limitations?

 

Kevin Simonson

 



NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: limitations on dependsOnMethods?

Cédric Beust ♔-2
Hi Kevin,

The method needs to be on the same class (or parent class) and be visible. Where is getCollectionSummary located?

-- 
Cédric




On Tue, Oct 4, 2011 at 11:09 AM, Kevin Simonson <[hidden email]> wrote:

I have a test method <updateCollection()> in my group “middle-phase” that has to be run after another test <getCollectionSummary(), also in group “middle-phase”, so <updateCollection()> looks like this:

 

@Test( dataProvider = “updColParms”, groups = { “middle-phase” }, dependsOnMethods = { “getCollectionSummary” })

public void updateCollection (    Collection original

                             , Collection… revisions)

                             Throws CdsAcceptanceException {

 

    original.setDbId( 0L);

    verifyUpdate( original, “created as”);

etc.

 

This compiles just fine, but when I go to run it my IntelliJ Console window says:

 

“C:\Program Files\Java\jdk1.6.0_23\bin\java” –agentlib:jdwp=transport=dt_socket,address=127.0.0.1:49914,suspend=y,server=n –ea –javaagent:C:\Users\kvnsmnsn\.IntelliJIdea10\system\groovyHotSwap\gragent.jar –Dfile.encoding=UTF-8 –classpath “C:\Program Fi …

Connected to the target VM, address: ‘127.0.0.1:49914’, transport: ‘socket’

org.testng.TestNGException:

org.familysearch.cds.acceptance.CollectionEndpointTest.updateCollection() is not allowed to depend on public void org.familysearch.cds.acceptance.CollectionEndpointTest.getCollectionSummary(java.lang.String,java.lang.String,java.lang.Integer) throws org.familysearch.cds.acceptance.client.CdsAcceptanceException

    at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:95)

    at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:244)

    at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:315)

Etc.

 

 

Anybody have any idea what this message means?  Are there limitations on which test methods can depend on which other test methods that is keeping me from getting this one method to depend on the other?  If so, what are those limitations?

 

Kevin Simonson

 



NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


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

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

RE: limitations on dependsOnMethods?

Kevin Simonson

Hi Cédric,

Both method <updateCollection()> and method <getCollectionSummary()> are in the same class.  I took the original code, moved it to a class named <Bug>, removed practically everything in each method, and I’m attaching what was left below.  Then I bring it up in IntelliJ, compile it (it compiles successfully), right click in the region of <updateCollection>, select <Debug “updateCollection()”>, and the console window comes up that says:

 

C:\Program Files\Java\jdk1.6.0_23\bin\java” –agentlib:jdwp=transport=dt_socket,address=127.0.0.1:62146,suspend=y,server=n –ea –javaagent:C:\Users\kvnsmnsn\.IntelliJIdea10\system\groovyHotSwap\gragent.jar –Dfile.encoding=UTF-8 –classpath “C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 10.0.3\plugins\testng\lib\testng-jdk15.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\alt-rt.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\alt-string.jar; etc.

Connected to the target VM, address: ‘127.0.0.1:62146’, transport: ‘socket’

org.testng.TestNGException:

org.familysearch.cds.acceptance.Bug.updateCollection() is not allowed to depend on public void org.familysearch.cds.acceptance.Bug.getCollectionSummary(java.lang.String,java.lang.String,java.lang.Integer)

    at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:95)

    at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:244)

    at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:315)

    at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:51)

    at org.testng.TestRunner.initMethods(TestRunner.java:464)

    at org.testng.TestRunner.init(TestRunner.java:228)

    etc.

 

Is it maybe because I just want it to execute <updateCollection()> and not <getCollectionSummary()>?  Is there a way in IntelliJ to tell it to execute both methods?

 

Anyhow, here’s the code:

 

package org.familysearch.cds.acceptance;

 

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

import org.testng.annotations.DataProvider;

import org.testng.Assert;

 

/**

* Created by IntelliJ IDEA.

* User: kvnsmnsn

* Date: 10/4/11

* Time: 2:27 PM

* To change this template use File | Settings | File Templates.

*/

public class Bug {

 

    @BeforeClass

    public void setUp () {

 

        System.out.println( "Executing <setUp()>.");

    }

 

    @DataProvider

    public Object[][] getCollSummParms () {

 

        return new Object[][] { new Object[] { "0", "1", 1} };

    }

 

    @Test(dataProvider = "getCollSummParms", groups = { "middle-phase" })

    public void getCollectionSummary (  String offset

                                     ,  String numToGet

                                     , Integer expctdNmbrCllctns) {

 

        Assert.assertEquals( "xyz", "xyz", "Amazing!");

    }

 

        @DataProvider

    public Object[][] updColParms () {

        return new Object[][] { new Object[] { "abc", "def" } };

    }

 

    @Test( dataProvider = "updColParms", groups = { "middle-phase" }, dependsOnMethods = { "getCollectionSummary" })

    public void updateCollection ( String left

                                 , String right) {

 

        Assert.assertEquals( "abc", "abc", "Wow!");

    }

}

 

Kevin Simonson

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Cédric Beust ?
Sent: Tuesday, October 04, 2011 12:20 PM
To: [hidden email]
Subject: Re: [testng-users] limitations on dependsOnMethods?

 

Hi Kevin,

 

The method needs to be on the same class (or parent class) and be visible. Where is getCollectionSummary located?


-- 

Cédric

 



NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: limitations on dependsOnMethods?

Cédric Beust ♔-2
Ah yes, if you are telling IDEA to only execute this method, I suspect that it will only include this method and no other, hence the message (TestNG is not seeing the other method it depends on).

If IDEA supports this, select both methods and run them. If not, you can create a testng.xml file that includes only these two methods and run that XML file.

-- 
Cédric




On Tue, Oct 4, 2011 at 2:47 PM, Kevin Simonson <[hidden email]> wrote:

Hi Cédric,

Both method <updateCollection()> and method <getCollectionSummary()> are in the same class.  I took the original code, moved it to a class named <Bug>, removed practically everything in each method, and I’m attaching what was left below.  Then I bring it up in IntelliJ, compile it (it compiles successfully), right click in the region of <updateCollection>, select <Debug “updateCollection()”>, and the console window comes up that says:

 

C:\Program Files\Java\jdk1.6.0_23\bin\java” –agentlib:jdwp=transport=dt_socket,address=127.0.0.1:62146,suspend=y,server=n –ea –javaagent:C:\Users\kvnsmnsn\.IntelliJIdea10\system\groovyHotSwap\gragent.jar –Dfile.encoding=UTF-8 –classpath “C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 10.0.3\plugins\testng\lib\testng-jdk15.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\alt-rt.jar;C:\Program Files\Java\jdk1.6.0_23\jre\lib\alt-string.jar; etc.

Connected to the target VM, address: ‘127.0.0.1:62146’, transport: ‘socket’

org.testng.TestNGException:

org.familysearch.cds.acceptance.Bug.updateCollection() is not allowed to depend on public void org.familysearch.cds.acceptance.Bug.getCollectionSummary(java.lang.String,java.lang.String,java.lang.Integer)

    at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:95)

    at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:244)

    at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:315)

    at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:51)

    at org.testng.TestRunner.initMethods(TestRunner.java:464)

    at org.testng.TestRunner.init(TestRunner.java:228)

    etc.

 

Is it maybe because I just want it to execute <updateCollection()> and not <getCollectionSummary()>?  Is there a way in IntelliJ to tell it to execute both methods?

 

Anyhow, here’s the code:

 

package org.familysearch.cds.acceptance;

 

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Test;

import org.testng.annotations.DataProvider;

import org.testng.Assert;

 

/**

* Created by IntelliJ IDEA.

* User: kvnsmnsn

* Date: 10/4/11

* Time: 2:27 PM

* To change this template use File | Settings | File Templates.

*/

public class Bug {

 

    @BeforeClass

    public void setUp () {

 

        System.out.println( "Executing <setUp()>.");

    }

 

    @DataProvider

    public Object[][] getCollSummParms () {

 

        return new Object[][] { new Object[] { "0", "1", 1} };

    }

 

    @Test(dataProvider = "getCollSummParms", groups = { "middle-phase" })

    public void getCollectionSummary (  String offset

                                     ,  String numToGet

                                     , Integer expctdNmbrCllctns) {

 

        Assert.assertEquals( "xyz", "xyz", "Amazing!");

    }

 

        @DataProvider

    public Object[][] updColParms () {

        return new Object[][] { new Object[] { "abc", "def" } };

    }

 

    @Test( dataProvider = "updColParms", groups = { "middle-phase" }, dependsOnMethods = { "getCollectionSummary" })

    public void updateCollection ( String left

                                 , String right) {

 

        Assert.assertEquals( "abc", "abc", "Wow!");

    }

}

 

Kevin Simonson

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Cédric Beust ?
Sent: Tuesday, October 04, 2011 12:20 PM
To: [hidden email]
Subject: Re: [testng-users] limitations on dependsOnMethods?

 

Hi Kevin,

 

The method needs to be on the same class (or parent class) and be visible. Where is getCollectionSummary located?


-- 

Cédric

 



NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


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

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

RE: limitations on dependsOnMethods?

Kevin Simonson

Cédric,

My work area is located at “C:\Sandbox\sourceCode4\cds2-root\cds-acceptance-tests\src\test”; from that directory the code I’ve been working on is at “java\org\familysearch\cds\acceptance\CollectionEndpointTest.java”, and I just created a file at “testng\testng.xml” with contents:

<test name="clTest">

  <classes>

    <class name="org.familysearch.cds.acceptance.CollectionEndpointTest">

      <methods>

        <include name="getCollectionSummary" />

        <include name="updateCollection" />

      </methods>

    </class>

  </classes>

</test>

 

I’m assuming that this is the right file to run the two mentioned tests.  Let me know if I don’t have it right!  At any rate, what do I do in IntelliJ to actually run these two methods?

Kevin Simonson

From: [hidden email] [mailto:[hidden email]] On Behalf Of Cédric Beust ?
Sent: Tuesday, October 04, 2011 4:07 PM
To: [hidden email]
Subject: Re: [testng-users] limitations on dependsOnMethods?

 

Ah yes, if you are telling IDEA to only execute this method, I suspect that it will only include this method and no other, hence the message (TestNG is not seeing the other method it depends on).

 

If IDEA supports this, select both methods and run them. If not, you can create a testng.xml file that includes only these two methods and run that XML file.


-- 

Cédric

 



NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: limitations on dependsOnMethods?

Cédric Beust ♔-2
You can probably just right click on that XML file and run it as a TestNG suite (not 100% sure since I'm an Eclipse user).

-- 
Cédric




On Tue, Oct 4, 2011 at 3:46 PM, Kevin Simonson <[hidden email]> wrote:

Cédric,

My work area is located at “C:\Sandbox\sourceCode4\cds2-root\cds-acceptance-tests\src\test”; from that directory the code I’ve been working on is at “java\org\familysearch\cds\acceptance\CollectionEndpointTest.java”, and I just created a file at “testng\testng.xml” with contents:

<test name="clTest">

  <classes>

    <class name="org.familysearch.cds.acceptance.CollectionEndpointTest">

      <methods>

        <include name="getCollectionSummary" />

        <include name="updateCollection" />

      </methods>

    </class>

  </classes>

</test>

 

I’m assuming that this is the right file to run the two mentioned tests.  Let me know if I don’t have it right!  At any rate, what do I do in IntelliJ to actually run these two methods?

Kevin Simonson

From: [hidden email] [mailto:[hidden email]] On Behalf Of Cédric Beust ?
Sent: Tuesday, October 04, 2011 4:07 PM


To: [hidden email]
Subject: Re: [testng-users] limitations on dependsOnMethods?

 

Ah yes, if you are telling IDEA to only execute this method, I suspect that it will only include this method and no other, hence the message (TestNG is not seeing the other method it depends on).

 

If IDEA supports this, select both methods and run them. If not, you can create a testng.xml file that includes only these two methods and run that XML file.


-- 

Cédric

 



NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


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

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: running groups of classes which inherit test methods from a base class

Cédric Beust ♔-2
In reply to this post by P. Hill-2
Hi Paul,

I reread your detailed message several times and I'm still a bit confused :-)

Would you mind posting a full example (I'm guessing the base class and two subclasses?)  that I can compile and explain what you'd like to see and you're seeing instead?

Thanks.

-- 
Cédric




On Mon, Oct 3, 2011 at 4:19 PM, P. Hill <[hidden email]> wrote:
I created a base class which contained an elaborate data provider and a series of (integration) tests which depend on being run in order.   I want to reuse the base class, because the only difference between two sets of runs
can be provided by a (gang of 4) factory method used within the test.  See Base class below which is the base class for two test classes Var1 and Var2.  I can create two suites each referring specifically to the classes Var1 and Var2 explicitly; This is great.

My only challenge is that I'd like to come up with a way to use groups to find Var1 or Var2 (group1 or group2, but never both), but as soon as I do that I can not see a way to group the test methods in the base (testSomeStuff below), so that only one of Var1 or Var2 is run in a suite depending on the groups I specify.

If I label tests in Base WITHOUT any groups, then they are never run because they are not in the right group.

If I label tests in Base with ALL possible groups (group1, group2) then ALL POSSIBLE SUBCLASSES are run, even though the sub classes are not in the right group, but the tests are.

If I use an exclude of the group1 when running group2 in the suite, I'm back to where I was when I specified no groups in the Base class, because all the Base tests are now excluded.

I did consider one alternative, overriding the Base test method in the subclasses, but this would not allow me to accomplish my original intent to re-use everything about test, including the dataprovider, it's dependsOnMethod, run awaysRun tag or any other annotations which are appropriate.

Are run groups not compatible with reusing a test method and it's annotations from a baseclass?
Am I missing some other solution?

-Paul

p.s. If the above isn't clear I can also paste in example Var1 and Var2 classes.  The only thing to note is that Var2 contains other tests to run which are not defined in the Base.

public abstract class Base {

   @DataProvider(name = "stuffer")
   public Object[][] provideStuff() {
       String commonButComplexStuff = "common stuff";
       return new Object[][] { { commonButComplexStuff, getSpecialStuff() } };
   }

   @Test()
   public void sanityCheck() {
       System.out.println("Sanity Check");
   }

   @Test(dataProvider = "stuffer", dependsOnMethods = "sanityCheck", alwaysRun = true)
   public void testSomeStuff(String stuff) {
       System.out.println("Testing using " + stuff + " and " + getSpecialStuff());
   }

   abstract protected String getSpecialStuff();
}

-Paul

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


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: running groups of classes which inherit test methods from a base class

P. Hill-2
Thanks for looking at my problem.
On 10/4/2011 11:43 PM, Cédric Beust ♔ wrote:
> Hi Paul,
>
> I reread your detailed message several times and I'm still a bit
> confused :-)
>
> Would you mind posting a full example (I'm guessing the base class and
> two subclasses?) that I can compile and explain what you'd like to see
> and you're seeing instead?
>

After playing with my example a bit I realize that the data provider,
despite being my motivation for creating the subclass, is irrelevant to
any confusion, so the example can be much simplified.

Goal: I want to define a test suite using groups and without having to
list specific classes, so that one subclass of a base class runs in one
test and the other subclass runs in another test. I don't mind using
group includes and excludes, I just don't see the right variation to
use. I could also divide things into more classes if that is required,
but that makes it harder to send helpful information recorded by the
common test on to a specific final test.

I can see where my desire might conflict with another use of a base test
class discussed this week on this list which is to run many subclass
variations all in the _same_ group because the group is mentioned on the
base class.

The reason I don't just call a non-test method in the base from each
subclass is that I was hoping to not repeat the test annotations. I
wished to list the appropriate annotations for the common test
(currently 3) in one location. Maybe this is the place to change my
approach to reusing the common method.

Running the following suite (in Eclipse) I get...
Sanity Check in Var1
Common Reusable Test in Var1
Sanity Check in Var2
Common Reusable Test in Var2
a specific test in Var2

What I want is no Var1s and only Var2s, so my expected run simply would be:

Sanity Check in Var2
Common Reusable Test in Var2
a specific test in Var2

Of course, eventually I'll have another <test> that does just Var1 (and
maybe others in that group) using a similar definition.

The files...
----------------- one suite
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Testing Variation 2" verbose="1" >
<test name="Using only one correct variation of the Base class" >
<groups>
<run>
<exclude name="var1"/>
<include name="var2"/>
<include name="base"/>
</run>
</groups>
<packages>
<package name="nging"/>
</packages>
<!-- Didn't really want to start listing specific classes, but I can
replace all the above with.
<classes>
<class name="nging.Var2"/>
</classes>
-->
</test>
</suite>
------------------------------------------ the base class Base.java
package nging;

import org.testng.annotations.*;

@Test ( groups="base" )
public abstract class Base {

@Test()
public void sanityCheck() {
System.out.println("Sanity Check in " + this.getClass().getSimpleName());
}

@Test(dependsOnMethods = "sanityCheck")
public void testSomeStuff() {
System.out.println("Common Reusable Test in " +
this.getClass().getSimpleName());
}
}
---------------------- the one variation of the base class Var1.java
package nging;

import org.testng.annotations.Test;

@Test(groups="var1")
public class Var1 extends Base {
@Test(dependsOnMethods="testSomeStuff")
public void var1More() {
System.out.println("a specific test in " + this.getClass().getSimpleName());
}
}
------------------- the other variation of the base class Var2.java
intended for another test in another suit.
package nging;

import org.testng.annotations.Test;

@Test(groups="var2")
public class Var2 extends Base {
@Test(dependsOnMethods="testSomeStuff")
public void var2More() {
System.out.println("a specific test in " + this.getClass().getSimpleName());
}
}


-Paul

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