How to run one single test with TestNG

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

How to run one single test with TestNG

Jessie
I'm using TestNG, RestAssure, and Gradle for REST web services testing.I use TestNG dataprovider loading test data from csv files.
Everything works fine. Unfortunately I can't find a way to run only one single test. For example, there are some test cases failed/skipped, I want to run only the case that caused the fail/skip. 

Right now I can do it by passing the row number of the test case that I want to run to datatprovider, only loads the specific test data.
example:
Enter code here...
public static Object[][] getTestDataFromCsvFile(String fileName, int rowNumberOfTestCaseWantToRun) {
    ...
    
    for (CSVRecord row : rows) {
    //To check if the test data row should be retrieved
if(selectedTestCaseIndexes != 0 && !row.contains(selectedTestCaseIndexes){
        continue;
}
...
}

I run test using xml file from command line and Jenkins. The problem I have is: I can't pass the test case number to dataprovider from Jenkins and command line. 

Any help would be greatly appreciated !

Yan

 

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to run one single test with TestNG

Krishnan Mahadevan
You should be able to pass via a JVM argument.

For e.g., you could enhance your test to optionally check for a JVM argument say -Dtestcase.index= which could follow one of the below three formats :
  1. It contains a single value such as "1" (or) "2" which indicates that you want to run a specific row. For e.g., -Dtestcase.index=1
  2. It contains a range value such as "1-5" which indicates you want to run it for rows 1 to 5. For e.g., -Dtestcase.index=1-5
  3. It contains comma separate index values. For e.g., -Dtestcase.index=1,3,8
You now enhance your getTestDataFromCsvFile() to check if System.getProperty("testcase.index") has any value in it or not. If there is any values, you parse it and honour its values, else your data provider method proceeds with reading all the rows.

Since its a JVM argument, you can easily pass it via Jenkins as well.

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/

On Thu, Feb 9, 2017 at 9:11 PM, Yanan <[hidden email]> wrote:
I'm using TestNG, RestAssure, and Gradle for REST web services testing.I use TestNG dataprovider loading test data from csv files.
Everything works fine. Unfortunately I can't find a way to run only one single test. For example, there are some test cases failed/skipped, I want to run only the case that caused the fail/skip. 

Right now I can do it by passing the row number of the test case that I want to run to datatprovider, only loads the specific test data.
example:
Enter code here...
public static Object[][] getTestDataFromCsvFile(String fileName, int rowNumberOfTestCaseWantToRun) {
    ...
    
    for (CSVRecord row : rows) {
    //To check if the test data row should be retrieved
if(selectedTestCaseIndexes != 0 && !row.contains(selectedTestCaseIndexes){
        continue;
}
...
}

I run test using xml file from command line and Jenkins. The problem I have is: I can't pass the test case number to dataprovider from Jenkins and command line. 

Any help would be greatly appreciated !

Yan

 

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to run one single test with TestNG

Jessie
Thank you for the detailed instruction.


On Thursday, February 9, 2017 at 9:42:46 PM UTC-5, Krishnan wrote:
You should be able to pass via a JVM argument.

For e.g., you could enhance your test to optionally check for a JVM argument say -Dtestcase.index= which could follow one of the below three formats :
  1. It contains a single value such as "1" (or) "2" which indicates that you want to run a specific row. For e.g., -Dtestcase.index=1
  2. It contains a range value such as "1-5" which indicates you want to run it for rows 1 to 5. For e.g., -Dtestcase.index=1-5
  3. It contains comma separate index values. For e.g., -Dtestcase.index=1,3,8
You now enhance your getTestDataFromCsvFile() to check if System.getProperty("testcase.index") has any value in it or not. If there is any values, you parse it and honour its values, else your data provider method proceeds with reading all the rows.

Since its a JVM argument, you can easily pass it via Jenkins as well.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/
My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

On Thu, Feb 9, 2017 at 9:11 PM, Yanan <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="O9f-O0f-BAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">bao...@...> wrote:
I'm using TestNG, RestAssure, and Gradle for REST web services testing.I use TestNG dataprovider loading test data from csv files.
Everything works fine. Unfortunately I can't find a way to run only one single test. For example, there are some test cases failed/skipped, I want to run only the case that caused the fail/skip. 

Right now I can do it by passing the row number of the test case that I want to run to datatprovider, only loads the specific test data.
example:
Enter code here...
public static Object[][] getTestDataFromCsvFile(String fileName, int rowNumberOfTestCaseWantToRun) {
    ...
    
    for (CSVRecord row : rows) {
    //To check if the test data row should be retrieved
if(selectedTestCaseIndexes != 0 && !row.contains(selectedTestCaseIndexes){
        continue;
}
...
}

I run test using xml file from command line and Jenkins. The problem I have is: I can't pass the test case number to dataprovider from Jenkins and command line. 

Any help would be greatly appreciated !

Yan

 

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="O9f-O0f-BAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="O9f-O0f-BAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.