loading...

automation test engineers and OOP

havryliuk profile image Oleksandr ・1 min read

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);
    }
}

instead of -

class Epic {
}

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

    @Test
    public void test() {
        assertNotNull(field);
    }
}

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.

Discussion

pic
Editor guide