简体   繁体   中英

Mockito: Mock object based on another

I have a mocked object, say Car porsche . It has 4 wheels, 1 windscreen,1 engine and name Porsche . This is done via when() and thenReturn() .

I want to create another mocked Car instance, say trabant , that will behave (again when() and thenReturn() ) exactly as the porsche instance, only will return a different name.

Is it possible to create the 2nd mock based on the 1st one without repeating all the when() and thenReturn() steps?

如何在测试中创建一个私有方法来设置给定模拟对象的共同期望?

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