2

I'm trying to refactor our testing framework to use TestNG rather than JUnit, and to do this we need to replace our pre-existing JUnit code with a TestNG equivalent. While it provides additional benefits and extensible functionality over JUnit in most cases, in the case of the @RunWith annotation, TestNG does not provide a very good solution.

TestNG's answer to the @RunWith annotation is to extend the AbstractTestNGSpringContextTests class, if possible I want to avoid this, as Java only supports single inheritance of classes and I do not want to place the limitation on my framework.

So the question is how else can I use TestNG with a Spring context aside from extending the abstract class?

This change is to take advantage of the many features and conveniences TestNG provides the JUnit does not to make our testing environment more efficient, including eventual parallelization of tests, grouping tests, data-driven testing framework using input files to reuse implementations, and simple aesthetics like adding test descriptions/simplifying test method names.

I tried reading the source code of the AbstractTestNGSpringContextTests for ideas, but it doesn't seem extendible outside of the context of a subclass

// Standard declaration for running Spring with TestNG
public class SpringTest1 extends AbstractTestNGSpringContextTests {

   @Autowired
   private DemoObj autoObj;

   //tests
}

We want something similar to the above but WITHOUT having to extend a superclass

user3466773
  • 176
  • 1
  • 2
  • 14

0 Answers0