简体   繁体   中英

Mock an object in a method that is not a parameter

I'm using EasyMock and junit to unit test a project I'm working on, but I'm stumped at this point. An example is below.

public ObjectNameHere methodOne(String location) {
    return this.SecondPart.getObjectByLocation(location);
}

I want to unit test this by checking that what the method returns is an instanceof ObjectNameHere... but how can I do that without mocking SecondPart (which requires I pass the method a mock object of SecondPart?) ??

Are you writing the test case for the method methodOne or getObjectByLocation . Because if it for methodOne then you need to mock the SecondPart object and expect some return value for the method getObjectByLocation . Or if it is for getObjectByLocation method then you have to write a test case for the SecondPart class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM