How do I disable a subclass test?

30 views
Skip to first unread message

Joshua Fox

unread,
Feb 27, 2018, 4:48:46 AM2/27/18
to testng-users
How do I disable subclass tests?

My design includes a base class with
@Test methods, and subclasses without their own @Test methods. Using enabled=false on the class level does not disable the subclass as you might hope.

// A.java public abstract class A { @Test public void testMethod(){ //... hookMethod(); //... } protected abstract void hookMethod(); } // B.java @Test (enabled=false) //doesn't disable test public class B extends A { protected void hookMethod() { // implementation } }

protected abstract void hookMethod(); } // C.java @Test //runs like B public class C extends A { protected void hookMethod() { // implementation } }

⇜Krishnan Mahadevan⇝

unread,
Feb 27, 2018, 6:12:30 AM2/27/18
to testng...@googlegroups.com
Joshua,

Please check if Ignoring tests would work for you here : http://testng.org/doc/documentation-main.html#ignore-tests

You need to be on the latest released version of TestNG (6.14.3 as of today)

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

Joshua Fox

unread,
Feb 27, 2018, 9:55:49 AM2/27/18
to testng-users
Does this allow disabling  tests on a subclass? Apparently not. See this from Cedric

⇜Krishnan Mahadevan⇝

unread,
Feb 27, 2018, 11:00:59 AM2/27/18
to testng...@googlegroups.com
Joshua,

I guess it does. I remember seeing unit tests that were added for checking that piece.
What happens when you try using that annotation ? 

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/

--

Joshua Fox

unread,
Feb 27, 2018, 11:18:50 AM2/27/18
to testng...@googlegroups.com
I ran a simple test with classes A, B, C as shown, and enabled=false does NOT disable the subclass's tests.

--
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/d_m7S0upJl8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users+unsubscribe@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
 

JOSHUA FOX
Director, Software Architecture | Freightos



T (Israel): +972-545691165 | T (US):  +1-3123400953  
Smooth shipping.



Krishnan Mahadevan

unread,
Feb 27, 2018, 10:43:51 PM2/27/18
to testng...@googlegroups.com

Joshua,

You mean you tried something like this using TestNG 6.14.3 ?

 

import org.testng.annotations.Test;

@Test
public class ParentClass {

   
public void testA() {
        System.
err.println("testA()");
    }
   
public void testB() {
        System.
err.println("testB()");
    }

}

 

import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

public class ChildClass extends ParentClass {
   
@Test
    @Ignore
   
public void testC() {
        System.
err.println("testC()");
    }

   
@Test
    @Ignore
   
public void testD() {
        System.
err.println("testD()");
    }
}

 

 

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/

Reply-To: <testng...@googlegroups.com>
Date: Tuesday, February 27, 2018 at 9:48 PM
To: <testng...@googlegroups.com>
Subject: Re: [testng-users] Re: How do I disable a subclass test?

--

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
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 a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/testng-users/d_m7S0upJl8/unsubscribe

.
To unsubscribe from this group and all its topics, send an email to
testng-users...@googlegroups.com.


To post to this group, send email to

JOSHUA FOX

Director, Software Architecture | Freightos

 

Image removed by sender.

 

T (Israel): +972-545691165 | T (US):  +1-3123400953  

Smooth shipping.

 

 

--

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

Joshua Fox

unread,
Feb 28, 2018, 4:50:07 AM2/28/18
to testng...@googlegroups.com
My class setup is a little different. The subclass has no @Test methods of its own.

Thank you for the  @Ignore annotation!  I guess it new https://github.com/cbeust/testng/pull/861 and seems to do the job.


--

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.


To post to this group, send email to
testng...@googlegroups.com.
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 a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/testng-users/d_m7S0upJl8/unsubscribe

.
To unsubscribe from this group and all its topics, send an email to
testng-users+unsubscribe@googlegroups.com.


To post to this group, send email to

 

 

JOSHUA FOX

Director, Software Architecture | Freightos

 

Image removed by sender.

 

T (Israel): +972-545691165 | T (US):  +1-3123400953  

Smooth shipping.

 

 

--

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+unsubscribe@googlegroups.com.


To post to this group, send email to

--
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/d_m7S0upJl8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users+unsubscribe@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
 

JOSHUA FOX
Director, Software Architecture | Freightos

Joshua Fox

unread,
Feb 28, 2018, 5:33:22 AM2/28/18
to testng...@googlegroups.com
Unfortunately, with the following code, mvn test still runs the  test, printing ChildClassTest#hook(), whether I use either or both of Ignore and enabled=false


// ========= ParentClassTest.java =========
package pkg1;

import org.testng.annotations.Test;

public  abstract class ParentClassTest {
@Test
public void testc() throws Exception {
hook();
}

protected abstract void hook();
}


// ========= ChildClassTest.java =========
package pkg1;

import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

//Neither of these annotations prevents the test from running
@Ignore
@Test(enabled=false)
public class ChildClassTest extends ParentClassTest {
@Override
protected void hook() {
System.out.println("ChildClassTest#hook()");

}
}



On Wed, Feb 28, 2018 at 11:49 AM, Joshua Fox <jos...@freightos.com> wrote:
My class setup is a little different. The subclass has no @Test methods of its own.

Thank you for the  @Ignore annotation!  I guess it new https://github.com/cbeust/testng/pull/861 and seems to do the job.

Krishnan Mahadevan

unread,
Feb 28, 2018, 10:45:19 PM2/28/18
to testng...@googlegroups.com

Joshua,

 

This is a bug. We need to get this fixed.

 

But with the way currently TestNG works, it may be a bit difficult.

 

You can track the discussions of this issue here : https://github.com/cbeust/testng/issues/1709

 

 

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: <testng...@googlegroups.com> on behalf of Joshua Fox <jos...@freightos.com>
Reply-To: <testng...@googlegroups.com>
Date: Wednesday, February 28, 2018 at 4:03 PM
To: <testng...@googlegroups.com>
Subject: Re: [testng-users] Re: How do I disable a subclass test?

 

Unfortunately, with the following code, mvn test still runs the  test, printing ChildClassTest#hook(), whether I use either or both of Ignore and enabled=false

--

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

--
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/d_m7S0upJl8/unsubscribe

.
To unsubscribe from this group and all its topics, send an email to
testng-users...@googlegroups.com.


To post to this group, send email to

JOSHUA FOX

Director, Software Architecture | Freightos

 

Error! Filename not specified.

 

T (Israel): +972-545691165 | T (US):  +1-3123400953  

Smooth shipping.

 

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

--
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/d_m7S0upJl8/unsubscribe

.
To unsubscribe from this group and all its topics, send an email to
testng-users...@googlegroups.com.


To post to this group, send email to

JOSHUA FOX

Director, Software Architecture | Freightos

 

https://www.freightos.com/wp-content/uploads/2015/10/Freightos-logo-1-e1464518092684.png

 

T (Israel): +972-545691165 | T (US):  +1-3123400953  

Smooth shipping.

 

 



 

--

 

 

JOSHUA FOX

Director, Software Architecture | Freightos

 

https://www.freightos.com/wp-content/uploads/2015/10/Freightos-logo-1-e1464518092684.png

 

T (Israel): +972-545691165 | T (US):  +1-3123400953  

Smooth shipping.

 

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

Joshua Fox

unread,
Mar 1, 2018, 1:32:20 AM3/1/18
to testng...@googlegroups.com
Thank you! Glad to know I uncovered a bug  😀

--

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.


To post to this group, send email to

--
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/d_m7S0upJl8/unsubscribe

.
To unsubscribe from this group and all its topics, send an email to
testng-users+unsubscribe@googlegroups.com.


To post to this group, send email to

 

 

JOSHUA FOX

Director, Software Architecture | Freightos

 

Error! Filename not specified.

 

T (Israel): +972-545691165 | T (US):  +1-3123400953  

Smooth shipping.

 

 

--
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+unsubscribe@googlegroups.com.


To post to this group, send email to

--
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/d_m7S0upJl8/unsubscribe

.
To unsubscribe from this group and all its topics, send an email to
testng-users+unsubscribe@googlegroups.com.


To post to this group, send email to

 

 

JOSHUA FOX

Director, Software Architecture | Freightos

 

https://www.freightos.com/wp-content/uploads/2015/10/Freightos-logo-1-e1464518092684.png

 

T (Israel): +972-545691165 | T (US):  +1-3123400953  

Smooth shipping.

 

 



 

--

 

 

JOSHUA FOX

Director, Software Architecture | Freightos

 

https://www.freightos.com/wp-content/uploads/2015/10/Freightos-logo-1-e1464518092684.png

 

T (Israel): +972-545691165 | T (US):  +1-3123400953  

Smooth shipping.

 

 

--
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+unsubscribe@googlegroups.com.


To post to this group, send email to

--
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/d_m7S0upJl8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users+unsubscribe@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
 

JOSHUA FOX
Director, Software Architecture | Freightos

Reply all
Reply to author
Forward
0 new messages