2

We have a lot of old unit tests which were written with Junit 3.x. I am tasked with porting them to our JUnit 4.x coding standard, which among things, forbids the use of "extends TestCase".

Some of the old tests have a call to super.setUp() which I need to now remove, however, I am not sure what is happening in that call. Can I just delete this line of code without worrying or should I replace it with something?

glenneroo
  • 1,908
  • 5
  • 30
  • 49

3 Answers3

2

Since setUp() is now called before each test, you can safely remove super.setUp().

Burkhard
  • 14,596
  • 22
  • 87
  • 108
  • 1
    Not necessarily. If the test had a base class other than `junit.framework.TestCase`, and that base class has a non-abstract `setUp()` call then the call to super.setUp() is absolutely necessary. If you have base classes after porting to JUnit4 (and with Rules they are seldom needed) then make the `@Before` and `@After` methods have good names and make them final. – NamshubWriter Feb 13 '13 at 22:32
0

Comment out the line and then run the test. If the test was written right the test result should give you the answer assuming the test was succeeding previously.

Tom
  • 3,006
  • 6
  • 33
  • 54
  • Unfortunately I don't have time to run any tests, I just need to get them to compile (without commenting everything out) and there are several hundred tests. I'll work on actually running tests in the upcoming weeks. – glenneroo Feb 13 '13 at 20:22
  • @glenneroo you need to make time to run each tests while as port them. If you can't make the time, port the tests later when you do have the time. – NamshubWriter Feb 13 '13 at 22:34
  • You have a valid point, however in my case it's unfortunately not an option. – glenneroo Feb 14 '13 at 01:15
0

super.setUp() is TestCase doesn't do anything and can be safely removed. You still need to keep the super.setUp() call if you are extending another class. However that one won't fail to compile, so you should be ok.

For example, suppose we have ATest extends BTest and BTest extends TestCase. You can safely remove the super.setUp() call from BTest and not ATest. Since the BTest one might do something, ATest still needs to call it.

Jeanne Boyarsky
  • 12,156
  • 2
  • 49
  • 59