DEV Community 👩‍💻👨‍💻

Oleksandr
Oleksandr

Posted on

automation test engineers and OOP

My fellow test engineers need to re-read OOP principles and understand their value and really start using them. E.g. they write -

class Epic {
    Type field = new Type();
}

class Test1 extends Epic {
    @Test
    public void test() {
        assertNotNull(field);
    }
}
Enter fullscreen mode Exit fullscreen mode

instead of -

class Epic {
}

class Test1 extends Epic {
    private Type field = new Type();

    @Test
    public void test() {
        assertNotNull(field);
    }
}
Enter fullscreen mode Exit fullscreen mode

Their reasoning is: "When we add another test under this epic and declare the same field, we will get a Sonar issue for duplicate fields."

My conclusion is they are still not right. You need to declare and initialise fields only in the class where you use it, not in a superclass hoping that someone some day will use it in another child class.

Top comments (0)

DEV

Thank you.

 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.