Regular expression to run all test class

265 views
Skip to first unread message

sunny sachdeva

unread,
Aug 24, 2015, 11:58:15 PM8/24/15
to testng-users
HI,

I want to know if we can provide regular expression in testng.xml. My requirement is that I want to run all the test classes inside a particular folder. Fpr ex  src/test/ModuleA contains 100 test classes.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Sanity" verbose="1" parallel="none"
preserve-order="true">

<test name="Sanity Test">
<classes>
<class name="com.demo.test.ModuleA.Class1" />
<class name="com.demo.test.ModuleA.Class2" />
<class name="com.demo.test.ModuleA.Class3" />
....and so on
</classes>
</test>
</suite>

I guess we can might achieve this using bean shell scripting but with my limited knowledge, I am not able to able to do so.

Can someone please help me in this.

Thanks in advance
Sunny

Krishnan Mahadevan

unread,
Aug 25, 2015, 3:44:30 AM8/25/15
to testng...@googlegroups.com
Why not just use packages ? Wouldn't that help ?

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, 7:20:52 AM8/25/15
to testng-users

+1 for the question!

I thought the same but in packages they may be multiple folders and each folder may have multiple files. Here, I would need to run cases based on folders instead of package. How can I do this?

Shawn McCarthy

unread,
Aug 25, 2015, 10:20:17 AM8/25/15
to testng-users
  <test name="All Tests" preserve-order="false">
    <packages>
      <package name="com.company.testarea1.*"></package>
    </packages>
  </test>

That will run all the tests in that package and sub packages

Krishnan Mahadevan

unread,
Aug 26, 2015, 4:35:47 AM8/26/15
to testng...@googlegroups.com
Here's how you can leverage beanshell to do this [ using this you can choose to selectively run one or more classes from a given package etc., ]

Please make sure that you go through the below links

My blog post which explains how to work with beanshell : https://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/
TestNG documentation, which explains what all is exposed by TestNG to a beanshell : http://testng.org/doc/documentation-main.html#beanshell

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
    <test name="Test">
        <method-selectors>
            <method-selector>
                <script language="beanshell">
                <![CDATA[regex = System.getProperty("classPattern");
                testngMethod.getRealClass().getCanonicalName().contains(regex); // feel free to change this to any other method exposed by the String class
                ]]>
                </script>
            </method-selector>
        </method-selectors>
        <packages>
              <package name="com.company.testarea1.*"/>
        </packages>
    </test> <!-- Test -->
</suite> <!-- Suite -->



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/

--

sunny sachdeva

unread,
Aug 31, 2015, 12:16:39 AM8/31/15
to testng-users
Thanks Krishnan. It worked

Regards

Sunny
Reply all
Reply to author
Forward
0 new messages