How to skip particular condition in testng?

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

How to skip particular condition in testng?

garvitagirotraev
Hi,

I am running test suite. I need to skip particular condition.
 
Class Util
{
        createdata(string data)
        {
             // some functionality
              getValue();
         }

public void getValue()
    {
      // some functionality
     }
}

Class MyData()
{
Util util = new Util();
util.createdata("test");
}

I need if string passed is test, getValue() should be skipped. I want to use SkipCondition of testng so that it can be reported in reporting too.

I should add in createdata method that if(data=="test"), throw new skip exception or i should define this in getValue() method.

Thanks !!

--
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 skip particular condition in testng?

⇜Krishnan Mahadevan⇝

Can you please add a bit more concrete example which shows how your tests are consuming this? Your question is kind of confusing.


On Wed, Nov 22, 2017, 11:01 <[hidden email]> wrote:
Hi,

I am running test suite. I need to skip particular condition.
 
Class Util
{
        createdata(string data)
        {
             // some functionality
              getValue();
         }

public void getValue()
    {
      // some functionality
     }
}

Class MyData()
{
Util util = new Util();
util.createdata("test");
}

I need if string passed is test, getValue() should be skipped. I want to use SkipCondition of testng so that it can be reported in reporting too.

I should add in createdata method that if(data=="test"), throw new skip exception or i should define this in getValue() method.

Thanks !!

--
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.
--

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 [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 skip particular condition in testng?

garvitagirotraev
I hope this example makes it clear:

Class util
{
     createChart(String parameter)
           {
            // functionality to create chart
            // call method to verify labels
            getAxisLabels()
           }

     public void GetAxislabels()
         {
          // functionality to assert x-axis and y-axis labels
         }
}

There is multiple classes using methods of util class, one of them is Pie Chart:
class PieChart
{
    @Test
     public void makePieChart()
      {
         createChart("company");
         createChart("year");
      }
}


Now i want to implement:
if(parameter.equalsTo("year")
skip calling getAxisLabels();


I tried implementing this way:
if(paramter.equlsTo("year")
{
   throw new SkipException(
                        "Skipping pie chart ");
            } else {
                getAxisLabels();
   }

This is working fine, condition is getting skipped. But when i see report, it shows :

Skipped makePieChart with error message printed.


But createChart("company"); is passed, exception is thrown on createChart("year"). Report shows whole test as skipped.
This is the correct way to use skip condition?

Thanks !!
On Wednesday, November 22, 2017 at 11:04:15 AM UTC+5:30, Krishnan Mahadevan wrote:

Can you please add a bit more concrete example which shows how your tests are consuming this? Your question is kind of confusing.


On Wed, Nov 22, 2017, 11:01 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="BFUdgNb7AgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">garvitag...@...> wrote:
Hi,

I am running test suite. I need to skip particular condition.
 
Class Util
{
        createdata(string data)
        {
             // some functionality
              getValue();
         }

public void getValue()
    {
      // some functionality
     }
}

Class MyData()
{
Util util = new Util();
util.createdata("test");
}

I need if string passed is test, getValue() should be skipped. I want to use SkipCondition of testng so that it can be reported in reporting too.

I should add in createdata method that if(data=="test"), throw new skip exception or i should define this in getValue() method.

Thanks !!

--
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="BFUdgNb7AgAJ" 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="BFUdgNb7AgAJ" 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.
--

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/

--
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 skip particular condition in testng?

⇜Krishnan Mahadevan⇝

Throwing a SkipCondition is obviously going to cause the @Test that raised this exception to be marked as skipped.

 

Why not do something like below :

 

if(! parameter.equalsTo("year") {

    getAxisLabels();

}

 

 

 

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/

 

From: <[hidden email]> on behalf of <[hidden email]>
Reply-To: <[hidden email]>
Date: Wednesday, November 22, 2017 at 12:14 PM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] How to skip particular condition in testng?

 

I hope this example makes it clear:

 

Class util

{

     createChart(String parameter)

           {

            // functionality to create chart

            // call method to verify labels

            getAxisLabels()

           }

 

     public void GetAxislabels()

         {

          // functionality to assert x-axis and y-axis labels

         }

}

 

There is multiple classes using methods of util class, one of them is Pie Chart:

class PieChart

{

    @Test

     public void makePieChart()

      {

         createChart("company");

         createChart("year");

      }

}

 

 

Now i want to implement:

if(parameter.equalsTo("year")

skip calling getAxisLabels();

 

 

I tried implementing this way:

if(paramter.equlsTo("year")

{

   throw new SkipException(

                        "Skipping pie chart ");

            } else {

                getAxisLabels();

   }

 

This is working fine, condition is getting skipped. But when i see report, it shows :

Skipped makePieChart with error message printed.

 

But createChart("company"); is passed, exception is thrown on createChart("year"). Report shows whole test as skipped.

This is the correct way to use skip condition?

 

Thanks !!
On Wednesday, November 22, 2017 at 11:04:15 AM UTC+5:30, Krishnan Mahadevan wrote:

Can you please add a bit more concrete example which shows how your tests are consuming this? Your question is kind of confusing.

 

On Wed, Nov 22, 2017, 11:01 <<a href="javascript:" target="_blank">garvitag...@...> wrote:

Hi,

 

I am running test suite. I need to skip particular condition.

 

Class Util

{

        createdata(string data)

        {

             // some functionality

              getValue();

         }

 

public void getValue()

    {

      // some functionality

     }

}

 

Class MyData()

{

Util util = new Util();

util.createdata("test");

}

 

I need if string passed is test, getValue() should be skipped. I want to use SkipCondition of testng so that it can be reported in reporting too.

 

I should add in createdata method that if(data=="test"), throw new skip exception or i should define this in getValue() method.

 

Thanks !!

--
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">testng-users...@....
To post to this group, send email to <a href="javascript:" target="_blank">testng...@....
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--

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 [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.