Everybody recommended to follow MVP or MVVM pattern to maintain code readability and testability. Now I am having doubts. Now I am learning unit testing and I'm writing the code in a formal way. Not using any patterns. Now my question, can I test my code like the following?
My main activity:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean testMethod(int value){
return value== 5?true:false;
}
}
My unit test class:
@RunWith(MockitoJUnitRunner.class)
public class ExampleUnitTest {
MainActivity mainActivity = new MainActivity();
@Test
public void testMethod(){
boolean result = mainActivity.testMethod(5);
assertEquals(true,result);
}
}
While running the test I did not receive any errors or issues. So is this the right way to test like this? Or what will happen if I follow this method? I am also starting to migrate my code to the MVP pattern, but I want to clear my doubts. Please let me know the reason why I should not follow the formal coding for unit testing.