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?

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

3 Comments

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 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.
You have a valid point, however in my case it's unfortunately not an option.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.