How do I test parameters inside a method itself. For example
class TestClass {
public void paraMethod(String para1, String para2) {
String testPara1 = para1;
String testPara2 = para2;
}
}
class TestingClass {
@Test
public void testParaMethod () throws Exception {
String myPara1 = "MyPara1";
String myPara2 = "MyPara2";
new TestClass().paraMethod(myPara1, myPara2);
}
}
Ok, so is it possible to test if the testPara1 and testPara2 are properly set to the values that I have passed?
Thanks.
It is neither possible nor desirable to test the values and state changes of local variables of a method. They are private details of the implementation, not something you are expected to test.
Instead, your tests should judge the correctness of a method by observing something visible from the outside, such as return values, interactions with mocked environment, or externally visible changes of the object’s state.