TestNG Rookie needs help

34 views
Skip to first unread message

Kaleem Uddin Mohammed Abdul

unread,
Aug 20, 2015, 10:45:04 AM8/20/15
to testng-users
Hi All,
I'm going through the documentation which is mentioned @http://testng.org/doc/documentation-main.html#annotationtransformers
I just completed the annotations part and I have the following queries


1. Why we are allowing more than one method to use the same annotation. In the below piece of code @BeforeMethod is used twice.
2. When I use alwaysRun=true,enabled=false, here the preference is always given to enable. Why?
3. The following is the output when I right clicked the TestNG.xml and said RunAs->TestNG. In this output, I can't find my Annotations output, Why?
[TestNG] Running:
  C:\Kaleem\EclipseWorkSpace\DellCSW\TestNG.xml

in test case 2
in test case 2
in test case 2
in test case 1

===============================================
Suite1
Total tests run: 4, Failures: 0, Skips: 0
===============================================
4. When I right click the .java file and  say Runas->TestNG the eclipse IDE  throws exception for not implementing Add and Delete method. Here, I don't implement any interface but why this error message?
Note: For this scenario I'm not including TestNG.xml file.

My Annotations:
 // test case 1
       @Test(dependsOnMethods="testCase2",groups={"checkinTests"})
       public void testCase1() {
          System.out.println("in test case 1");
       }
    
       // test case 2
       @Test(alwaysRun=true,enabled=false,invocationCount=3,groups={"checkinTests"})
       public void testCase2() {
          System.out.println("in test case 2");
       }

       @BeforeMethod
       public void beforeMethod() {
          System.out.println("in beforeMethod");
       }
       @BeforeMethod
       public void beforeMethod1() {
          System.out.println("in beforeMethod");
       }
       @AfterMethod
       public void afterMethod() {
          System.out.println("in afterMethod");
       }

       @BeforeClass
       public void beforeClass() {
          System.out.println("in beforeClass");
       }

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

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

       @AfterTest
       public void afterTest() {
          System.out.println("in afterTest");
       }

       @BeforeSuite
       public void beforeSuite() {
          System.out.println("in beforeSuite");
       }

       @AfterSuite
       public void afterSuite() {
          System.out.println("in afterSuite");
       }
      
       @BeforeGroups
       public void beforeGroup() {
          System.out.println("in beforeGroup");
       }

       @AfterGroups
       public void afterGroup() {
          System.out.println("in afterGroup");
       }

My TestNG.xml file:
<suite name="Suite1" verbose="1" >
 
  <test name="Regression1">
    <classes>
      <class name="POC"/>
    </classes>
    <groups>
    <run>
      <exclude name="brokenTests"  />
      <include name="checkinTests"  />
    </run>
  </groups>
   
  </test>
</suite>

Thanks,
Kaleem.

Cédric Beust ♔

unread,
Aug 20, 2015, 10:50:41 AM8/20/15
to testng...@googlegroups.com

On Wed, Aug 19, 2015 at 10:38 PM, Kaleem Uddin Mohammed Abdul <makale...@gmail.com> wrote:

1. Why we are allowing more than one method to use the same annotation. In the below piece of code @BeforeMethod is used twice.

It’s convenient to allow multiple methods, for example when you have superclasses that also have these annotations. Note that the ordering is not specified.

2. When I use alwaysRun=true,enabled=false, here the preference is always given to enable. Why?

enabled is interpreted first and every method that has it set to false is removed from the set of test methods that will later be considered for inclusion in the test.

-- 
Cédric

Kaleem Uddin Mohammed Abdul

unread,
Aug 24, 2015, 1:39:23 AM8/24/15
to testng-users
Thanks Cédric!
Can someone please answer my remaining questions!

Thanks in advance!
Regards,
Kaleem.

Krishnan Mahadevan

unread,
Aug 24, 2015, 11:34:01 PM8/24/15
to testng...@googlegroups.com
>>>>>3. The following is the output when I right clicked the TestNG.xml and said RunAs->TestNG. In this output, I can't find my Annotations output, Why?

This is because your suite is running tests based on groups but none of your configuration methods are either part of any group nor do they have the attribute alwaysRun=true

>>>>>4. When I right click the .java file and  say Runas->TestNG the eclipse IDE  throws exception for not implementing Add and Delete method. Here, I don't implement any interface but why this error message?

It would be difficult to answer this question, because we don't know on what class you right clicked and tried this. We also don't know what exception you are talking about. This doesn't seem to have anything to do with TestNG is what my first thought would be on this!


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Kaleem Uddin Mohammed Abdul

unread,
Aug 25, 2015, 1:14:04 AM8/25/15
to testng-users
Thanks Krishna for Clarification!

I'm not able to re-produce the issue#4. I will keep you update whenever I encounter this issue.


Regards,
Kaleem.

On Thursday, August 20, 2015 at 8:15:04 PM UTC+5:30, Kaleem Uddin Mohammed Abdul wrote:
Reply all
Reply to author
Forward
0 new messages