Can I get the suite name from inside a test?

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

Can I get the suite name from inside a test?

cytoe
I need to get the suite name and report output directory from with in test method.  I this possible?

thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Can I get the suite name from inside a test?

Cédric Beust ♔
Hi Cytoe,

On 1/28/07, cytoe <[hidden email]> wrote:


I need to get the suite name and report output directory from with in test
method.  I this possible?

Not directly, but that's what DataProviders are for:

@DataProvider
public Object[][] dp(ITestContext tc) {
  return new Object[][] {
    new Object[] { tc }
  }
}

@Test(dataProvider = "dp")
public void dummyTest(ITestContext tc) {
  String name = tc.getName();
  String outputDirectory = tc.getOutputDirectory ();
}

Would this work for you?

--
Cédric
--~--~---------~--~----~------------~-------~--~----~
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: Can I get the suite name from inside a test?

cytoe
Hi Cedric,

That could work as a work around...but it's sorta ugly and adds duplication.  Also, I would not be able to do this in a @BeforeClass since DataProviders don't aren't available there.  My need is to write to the same directory as the report directory.  Using a dataprovider  would require that I describe the suite name (which I could use to contruct the report dir from) in more than one place.

Thanks,
Ron

Cédric Beust ♔ wrote
Hi Cytoe,

On 1/28/07, cytoe <cytoe@msn.com> wrote:
>
>
>
> I need to get the suite name and report output directory from with in test
> method.  I this possible?


Not directly, but that's what DataProviders are for:

@DataProvider
public Object[][] dp(ITestContext tc) {
  return new Object[][] {
    new Object[] { tc }
  }
}

@Test(dataProvider = "dp")
public void dummyTest(ITestContext tc) {
  String name = tc.getName();
  String outputDirectory = tc.getOutputDirectory();
}

Would this work for you?

--
Cédric

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users-unsubscribe@googlegroups.com
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: Can I get the suite name from inside a test?

Cédric Beust ♔
The advantage of this approach is that it doesn't require any ugly static global function and it's as close as you can get to parameter injection.

How would you like to be able to retrieve this information from inside the test method?

--
Cedric


On 1/29/07, cytoe <[hidden email]> wrote:


Hi Cedric,

That could work as a work around...but it's sorta ugly and adds duplication.
Also, I would not be able to do this in a @BeforeClass since DataProviders
don't aren't available there.  My need is to write to the same directory as
the report directory.  Using a dataprovider  would require that I describe
the suite name (which I could use to contruct the report dir from) in more
than one place.

Thanks,
Ron


Cédric Beust ♔ wrote:

>
> Hi Cytoe,
>
> On 1/28/07, cytoe <[hidden email]> wrote:
>>
>>
>>
>> I need to get the suite name and report output directory from with in
>> test
>> method.  I this possible?
>
>
> Not directly, but that's what DataProviders are for:
>
> @DataProvider
> public Object[][] dp(ITestContext tc) {
>   return new Object[][] {
>     new Object[] { tc }
>   }
> }
>
> @Test(dataProvider = "dp")
> public void dummyTest(ITestContext tc) {
>   String name = tc.getName();
>   String outputDirectory = tc.getOutputDirectory();
> }
>
> Would this work for you?
>
> --
> Cédric
>
> >
>
>

--
View this message in context: http://www.nabble.com/Can-I-get-the-suite-name-from-inside-a-test--tf3134129.html#a8695283
Sent from the testng-users mailing list archive at Nabble.com.

--~--~---------~--~----~------------~-------~--~----~
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: Can I get the suite name from inside a test?

cytoe
I was thinking more along the lines of access to some internal variables in testng.  When testng is running, it knows what suite it is in, right?  A public static variable or method to access this doesn't seem to bad.  I haven't really looked at the testng source...perhaps I could get this info by doing:  TestNG.getCurrentSuite();  

Cédric Beust ♔ wrote
The advantage of this approach is that it doesn't require any ugly static
global function and it's as close as you can get to parameter injection.

How would you like to be able to retrieve this information from inside the
test method?

--
Cedric


On 1/29/07, cytoe <cytoe@msn.com> wrote:
>
>
>
> Hi Cedric,
>
> That could work as a work around...but it's sorta ugly and adds
> duplication.
> Also, I would not be able to do this in a @BeforeClass since DataProviders
> don't aren't available there.  My need is to write to the same directory
> as
> the report directory.  Using a dataprovider  would require that I describe
> the suite name (which I could use to contruct the report dir from) in more
> than one place.
>
> Thanks,
> Ron
>
>
> Cédric Beust ♔ wrote:
> >
> > Hi Cytoe,
> >
> > On 1/28/07, cytoe <cytoe@msn.com> wrote:
> >>
> >>
> >>
> >> I need to get the suite name and report output directory from with in
> >> test
> >> method.  I this possible?
> >
> >
> > Not directly, but that's what DataProviders are for:
> >
> > @DataProvider
> > public Object[][] dp(ITestContext tc) {
> >   return new Object[][] {
> >     new Object[] { tc }
> >   }
> > }
> >
> > @Test(dataProvider = "dp")
> > public void dummyTest(ITestContext tc) {
> >   String name = tc.getName();
> >   String outputDirectory = tc.getOutputDirectory();
> > }
> >
> > Would this work for you?
> >
> > --
> > Cédric
> >
> > >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Can-I-get-the-suite-name-from-inside-a-test--tf3134129.html#a8695283
> Sent from the testng-users mailing list archive at Nabble.com.
>
>
> >
>


--
Cédric

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users-unsubscribe@googlegroups.com
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: Can I get the suite name from inside a test?

Cédric Beust ♔


On 1/29/07, cytoe <[hidden email]> wrote:


I was thinking more along the lines of access to some internal variables in
testng.  When testng is running, it knows what suite it is in, right?  A
public static variable or method to access this doesn't seem to bad.

Global statics are always bad :-)

TestNG is heavily multi-threaded, so introducing global statics would complicate the logic quite a bit.  It would also not work well inside a container or in the distributed version.  Of course, statics make testing much more difficult as well.

Injection is by far a better approach since it doesn't have any of these drawbacks.

What bothers you about the DataProvider solution exactly?

--
Cédric
--~--~---------~--~----~------------~-------~--~----~
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: Can I get the suite name from inside a test?

cytoe
Ya. you got a point about the statics and multi-threaded.  My main problem with passing in the suite name is that it must be aligned w/ the testng xml.  I'm using testng in a automated test framework, so this alignment might be difficult.
Cédric Beust ♔ wrote
On 1/29/07, cytoe <cytoe@msn.com> wrote:
>
>
>
> I was thinking more along the lines of access to some internal variables
> in
> testng.  When testng is running, it knows what suite it is in, right?  A
> public static variable or method to access this doesn't seem to bad.


Global statics are always bad :-)

TestNG is heavily multi-threaded, so introducing global statics would
complicate the logic quite a bit.  It would also not work well inside a
container or in the distributed version.  Of course, statics make testing
much more difficult as well.

Injection is by far a better approach since it doesn't have any of these
drawbacks.

What bothers you about the DataProvider solution exactly?

--
Cédric

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users-unsubscribe@googlegroups.com
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: Can I get the suite name from inside a test?

Cédric Beust ♔


On 1/29/07, cytoe <[hidden email]> wrote:


Ya. you got a point about the statics and multi-threaded.  My main problem
with passing in the suite name is that it must be aligned w/ the testng xml.
I'm using testng in a automated test framework, so this alignment might be
difficult.

I'm not sure I understand what you mean by "aligned"?

Anyway, I made a slight modification to ISuite, and if you download:

http://testng.org/testng-5.6beta-jdk15.jar

, you will be able to use the following code:

  @DataProvider(name = "A")
  protected Object[][] dp(ITestContext tc) {
    return new Object[][] {
        { tc }
    };
  }

  @Test(dataProvider = "A")
  public void testA(ITestContext tc) {
    System.out.println("SUITE NAME:" + tc.getSuite().getXmlSuite().getName());
  }

Your test methods now have access to the entire content of the testng.xml file they belong to.

Let me know what you think.

--
Cédric
--~--~---------~--~----~------------~-------~--~----~
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: Can I get the suite name from inside a test?

cytoe
Cool. sounds like the new code will help.  However, If I'm running tests w/o an xml file, then I still have a problem.  If I need to use an xml file for this to work, I can live w/ it.

Thanks!
Ron
 
Cédric Beust ♔ wrote
On 1/29/07, cytoe <cytoe@msn.com> wrote:
>
>
>
> Ya. you got a point about the statics and multi-threaded.  My main problem
> with passing in the suite name is that it must be aligned w/ the testng
> xml.
> I'm using testng in a automated test framework, so this alignment might be
> difficult.


I'm not sure I understand what you mean by "aligned"?

Anyway, I made a slight modification to ISuite, and if you download:

http://testng.org/testng-5.6beta-jdk15.jar

, you will be able to use the following code:

  @DataProvider(name = "A")
  protected Object[][] dp(ITestContext tc) {
    return new Object[][] {
        { tc }
    };
  }

  @Test(dataProvider = "A")
  public void testA(ITestContext tc) {
    System.out.println("SUITE NAME:" + tc.getSuite
().getXmlSuite().getName());
  }

Your test methods now have access to the entire content of the
testng.xmlfile they belong to.

Let me know what you think.

--
Cédric

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users-unsubscribe@googlegroups.com
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: Can I get the suite name from inside a test?

Cédric Beust ♔
If you're not using an XML file, TestNG will generate a "fake" one for you, and you can set its name yourself if you don't like the default one.

--
Cedric


On 1/29/07, cytoe <[hidden email]> wrote:


Cool. sounds like the new code will help.  However, If I'm running tests w/o
an xml file, then I still have a problem.  If I need to use an xml file for
this to work, I can live w/ it.

Thanks!
Ron


Cédric Beust ♔ wrote:

>
> On 1/29/07, cytoe <[hidden email]> wrote:
>>
>>
>>
>> Ya. you got a point about the statics and multi-threaded.  My main
>> problem
>> with passing in the suite name is that it must be aligned w/ the testng
>> xml.
>> I'm using testng in a automated test framework, so this alignment might
>> be
>> difficult.
>
>
> I'm not sure I understand what you mean by "aligned"?
>
> Anyway, I made a slight modification to ISuite, and if you download:
>
> http://testng.org/testng-5.6beta-jdk15.jar
>
> , you will be able to use the following code:
>
>   @DataProvider(name = "A")
>   protected Object[][] dp(ITestContext tc) {
>     return new Object[][] {
>         { tc }
>     };
>   }
>
>   @Test(dataProvider = "A")
>   public void testA(ITestContext tc) {
>     System.out.println("SUITE NAME:" + tc.getSuite
> ().getXmlSuite().getName());

>   }
>
> Your test methods now have access to the entire content of the
> testng.xmlfile they belong to.
>
> Let me know what you think.
>
> --
> Cédric
>
> >
>
>

--
View this message in context: http://www.nabble.com/Can-I-get-the-suite-name-from-inside-a-test--tf3134129.html#a8701387
Sent from the testng-users mailing list archive at Nabble.com.







--
Cédric
--~--~---------~--~----~------------~-------~--~----~
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: Can I get the suite name from inside a test?

cytoe
In reply to this post by Cédric Beust ♔
Can I get eclipse_testng_5.6beta?  I checked out the eclipse testng svn, but didn't see any 5.6beta label.  Also, there's no ant file...so I'm not sure how to create the plugin.

Thanks,
Ron
Cédric Beust ♔ wrote
On 1/29/07, cytoe <cytoe@msn.com> wrote:
>
>
>
> Ya. you got a point about the statics and multi-threaded.  My main problem
> with passing in the suite name is that it must be aligned w/ the testng
> xml.
> I'm using testng in a automated test framework, so this alignment might be
> difficult.


I'm not sure I understand what you mean by "aligned"?

Anyway, I made a slight modification to ISuite, and if you download:

http://testng.org/testng-5.6beta-jdk15.jar

, you will be able to use the following code:

  @DataProvider(name = "A")
  protected Object[][] dp(ITestContext tc) {
    return new Object[][] {
        { tc }
    };
  }

  @Test(dataProvider = "A")
  public void testA(ITestContext tc) {
    System.out.println("SUITE NAME:" + tc.getSuite
().getXmlSuite().getName());
  }

Your test methods now have access to the entire content of the
testng.xmlfile they belong to.

Let me know what you think.

--
Cédric

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users-unsubscribe@googlegroups.com
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: Can I get the suite name from inside a test?

cytoe
To get the eclipse plugin working, I just hacked and wacked.  Copied the beta jar into the eclipse testng plugin (org.testng.eclipse_5.5.0.0\lib) and renamed to testng-jdk15.jar.  Works great:)

thanks,
Ron
cytoe wrote
Can I get eclipse_testng_5.6beta?  I checked out the eclipse testng svn, but didn't see any 5.6beta label.  Also, there's no ant file...so I'm not sure how to create the plugin.

Thanks,
Ron
Cédric Beust ♔ wrote
On 1/29/07, cytoe <cytoe@msn.com> wrote:
>
>
>
> Ya. you got a point about the statics and multi-threaded.  My main problem
> with passing in the suite name is that it must be aligned w/ the testng
> xml.
> I'm using testng in a automated test framework, so this alignment might be
> difficult.


I'm not sure I understand what you mean by "aligned"?

Anyway, I made a slight modification to ISuite, and if you download:

http://testng.org/testng-5.6beta-jdk15.jar

, you will be able to use the following code:

  @DataProvider(name = "A")
  protected Object[][] dp(ITestContext tc) {
    return new Object[][] {
        { tc }
    };
  }

  @Test(dataProvider = "A")
  public void testA(ITestContext tc) {
    System.out.println("SUITE NAME:" + tc.getSuite
().getXmlSuite().getName());
  }

Your test methods now have access to the entire content of the
testng.xmlfile they belong to.

Let me know what you think.

--
Cédric

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com
To unsubscribe from this group, send email to testng-users-unsubscribe@googlegroups.com
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: Can I get the suite name from inside a test?

Cédric Beust ♔
No, you'll have to replace the jar file inside the plug-in yourself for now...

--
Cedric


On 1/31/07, cytoe <[hidden email]> wrote:


To get the eclipse plugin working, I just hacked and wacked.  Copied the beta
jar into the eclipse testng plugin (org.testng.eclipse_5.5.0.0\lib) and
renamed to testng-jdk15.jar.  Works great:)

thanks,
Ron

cytoe wrote:

>
> Can I get eclipse_testng_5.6beta?  I checked out the eclipse testng svn,
> but didn't see any 5.6beta label.  Also, there's no ant file...so I'm not
> sure how to create the plugin.
>
> Thanks,
> Ron
>
> Cédric Beust ♔ wrote:
>>
>> On 1/29/07, cytoe <[hidden email]> wrote:

>>>
>>>
>>>
>>> Ya. you got a point about the statics and multi-threaded.  My main
>>> problem
>>> with passing in the suite name is that it must be aligned w/ the testng
>>> xml.
>>> I'm using testng in a automated test framework, so this alignment might
>>> be
>>> difficult.
>>
>>
>> I'm not sure I understand what you mean by "aligned"?
>>
>> Anyway, I made a slight modification to ISuite, and if you download:
>>
>> http://testng.org/testng-5.6beta-jdk15.jar
>>
>> , you will be able to use the following code:
>>
>>   @DataProvider(name = "A")
>>   protected Object[][] dp(ITestContext tc) {
>>     return new Object[][] {
>>         { tc }
>>     };
>>   }
>>
>>   @Test(dataProvider = "A")
>>   public void testA(ITestContext tc) {
>>     System.out.println("SUITE NAME:" + tc.getSuite
>> ().getXmlSuite().getName());
>>   }
>>
>> Your test methods now have access to the entire content of the
>> testng.xmlfile they belong to.
>>
>> Let me know what you think.
>>
>> --
>> Cédric
>>
>> >>
>>
>>
>
>

--
View this message in context: http://www.nabble.com/Can-I-get-the-suite-name-from-inside-a-test--tf3134129.html#a8737874
Sent from the testng-users mailing list archive at Nabble.com.







--
Cédric
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---