0

I have a JUNIT test class that contains a few test methods. Now I have a another test class which is parameterized with a bunch of parameters and I have a specific use case(test) that i'd like to keep in this new class. However, I do want to run the other tests in the earlier test class as well but I do not want to duplicate code.

So i inherit that class, and the tests run without an issue. But I am wondering if this is good testing design.

arjunj
  • 1,436
  • 1
  • 16
  • 28

1 Answers1

2

There is no harm of inheriting some other test class.

Test class is just the same other class which we have in Java. However, if in your test you build big hierarchy it might happen that many tests will be dependent on some parent class. Thus, it might happen that if your test class fails you would need to check all other classes which have some influence on the test that fails. This might be challenging. In general as I understand the test should be written as individual independent part which will be testing some specific case.

Rufi
  • 2,529
  • 1
  • 20
  • 41