0

While Constructing parameterized test cases in JUnit4,we are using Super keyword.I didn't understand what is the use of Super keyword here.What happens if this keyword is not used here? I am attaching a JUnit parameterized test case for string reverse as an example.

    package BasicTesting;
    import static org.junit.Assert.*;
    import java.util.Arrays;
    import java.util.Collection;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.junit.runners.Parameterized;
    import org.junit.runners.Parameterized.Parameters;
    @RunWith(Parameterized.class)
    public class Corrected_String_Test {
        public Corrected_String_Test(String input, String expected) {
            super();
            this.input = input;
            this.expected = expected;
            }
        Corrected_StringRev ob=new Corrected_StringRev();
        private String input;
        private String expected;
        @Parameters
        public static Collection<String[]> testConditions() {
    
            String expected[][]= {{"acd","dca"},{"12d","d21"},{"j h","h j"},{"  hg","  gh"},,{"&*","*&"}};
            
            return Arrays.asList(expected);
        }
        @Test
        public void RevStringtest() {
            assertEquals(expected,ob.reverseString(input));
            }
        }

Please help me to find answer.Thanks in adavance!

Julie
  • 1
  • 5

1 Answers1

0

super() will call the default, no args constructor of the super class. In your case, there is no superclass (besides Object), so there's no effect of having it here.

Erik Pragt
  • 13,513
  • 11
  • 58
  • 64
  • And even if there was a different superclass, it would still do nothing, as the default (parameterless) constructor of the superclass would be called anyway. – tgdavies Jul 01 '22 at 04:00