简体   繁体   中英

Spring and Mock Framework integration

I am looking for the mock framework with good integration with spring. I've used mockito and it is good framework but spring integration via springockito IMHO, is not good. So, Could you help me to chose good Mock Framework with good integration with Spring ? Thanks.

What is wrong with Springockito ? I like it for readabiltity i simplicity :)

import static org.mockito.BDDMockito.*;
import org.kubek2k.springockito.annotations.*;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class, 
     loader = SpringockitoAnnotatedContextLoader.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class MainControllerTest {

    @Autowired
    MainController mainController;

    @Autowired
    @ReplaceWithMock
    FooService fooService;

    @Test
    public void shouldGetBar() {
        //given
        given(fooService.result("foo")).willReturn("bar");

        //when
        Bar bar build = fooService.getBar("foo");

        //then
        assertThat(bar).isNotNull();
    }
}

Dependencies: org.kubek2k:springockito-annotations:1.0.9

是的,我只是想,我可以创建一些嘲笑util类,并在不使用springockito的情况下通过spring使用factory-method来使用它,感谢所有问题的解决:)

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