Fwd: TestNG query - BeforeClass not running

668 views
Skip to first unread message

Prasad KTM

unread,
Aug 24, 2015, 6:26:09 PM8/24/15
to testng...@googlegroups.com
Hi,

I'm Prasad, & this is my 1st email to the group.
I'm in the process of learning automation using Selenium & TestNG.
I'm here to seek your expertise in solving an issue.

I have written a small program (as seen below)
I'm unable to execute the method which is annotated with @BeforeClass

Not sure what I'm missing here.


Program:
package com.abc.neuro.common;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.xml.XmlTest;

public class LaunchUi {

@BeforeSuite
public void beforeSuite(XmlTest Config) throws Exception {
System.out.println("Inside @BeforeSuite");
}

@BeforeTest
public void launchNeuro(XmlTest Config) throws Exception {
System.out.println("Inside @BeforeTest");
}

@BeforeClass
public void beforeClass(XmlTest Config) throws Exception {
System.out.println("Inside @BeforeClass");
}

}

Output:
[TestNG] Running:
  C:\p4\Neuro\Neuro\Neuro\TestNG.xml

Inside @BeforeSuite
Inside @BeforeTest

===============================================
Neuro
Total tests run: 0, Failures: 0, Skips: 0
===============================================


XML file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Neuro">
<parameter name="screenshot" value="No"> <!--To take screen shot.--></parameter>
<parameter name="neuro_url" value="http://www.google.co.in"> <!--Neuro URL.--></parameter>
<parameter name="email" value="au...@netapp.com"> <!--Login email address .--></parameter>
<parameter name="password" value="auto"> <!--Login password .--></parameter>
  <test name="test1">
<classes>
<class name="com.abc.neuro.common.LaunchUi"/>
</classes>
</test>
</suite>

Shawn McCarthy

unread,
Aug 24, 2015, 8:29:25 PM8/24/15
to testng-users
Krishnan already answered on the selenium users group :

"
The answer to your question : Your Class doesn't have any @Test annotated test methods. So there is no reason for the @BeforeClass to be executed.
Please add atleast one @Test annotated test method to your test class and try again.
"

Prasad KTM

unread,
Aug 25, 2015, 12:24:34 PM8/25/15
to testng-users
Thanks Shawn & Krishnan.

I'm able to run my Tests now, including BeforeClass.
But is there an easy way to debug the issues related to TestNg.

Until there is any exception, TestNg does not seem to throw any error.

Shawn McCarthy

unread,
Aug 25, 2015, 1:09:41 PM8/25/15
to testng-users
When would you like to debug your test? I don't think I understand your question.

Krishnan Mahadevan

unread,
Aug 26, 2015, 4:27:45 AM8/26/15
to testng...@googlegroups.com
In this case, TestNG doesn't treat this as a problem but only an incorrect way of it being used. That is why it doesn't warn/throw an error at you.
Debugging is going to be the same concept, be it you use TestNG or any other library for that matter. All you would need to do is setup breakpoints at the place wherein execution begins [ In the case of TestNG you should start looking at the TestNG.run() method ] and then step through the execution to figure out what went wrong where !

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.

Prasad KTM

unread,
Aug 26, 2015, 9:44:00 AM8/26/15
to testng...@googlegroups.com
Thanks Krishnan. This helps. 

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/8x0zGIbfdqo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages