Like to know which one is good.
I have to keep some JUnit test data in a different file. Lets call it as TestingData.java. I thought of doing it in two ways.
First Way
TestingData.java
public class TestingData {
protected String getHelloWorld() {
return "Hello World";
}
}
Second Way
TestingData.java
public class TestingData {
public static String getHelloWorld() {
return "Hello World";
}
}
I can call the First Way like this in my testing service by extends TestingData class
@RunWith(MockitoJUnitRunner.class)
public class SomeServiceTest extends TestingData {
@Test
public void helloWorldTest() {
assertEquals("Hello World", getHelloWorld());
}
}
calling Second Way in my testing service by calling the static function TestingData.getHelloWorld()
@RunWith(MockitoJUnitRunner.class)
public class SomeServiceTest {
@Test
public void helloWorldTest() {
assertEquals("Hello World", TestingData.getHelloWorld());
}
}
Like to know which way is better in clean code principle