I am just wondering how can I create Mock object to test code like:
public class MyTest
{
private A a;
public MyTest()
{
a=new A(100,101);
}
}
?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Code that instantiates objects using
newdirectly makes testing difficult. By using the Factory pattern you move the creation of the object outside of the code to be tested. This gives you a place to inject a mock object and/or mock factory.Now you can pass in a mock factory in the test that will create a mock
Aor anAof your choosing. Let’s use Mockito to create the mock factory.