简体   繁体   English

Spring和Mock框架集成

[英]Spring and Mock Framework integration

I am looking for the mock framework with good integration with spring. 我正在寻找与Spring良好集成的模拟框架。 I've used mockito and it is good framework but spring integration via springockito IMHO, is not good. 我使用过模仿,它是一个很好的框架,但是通过springockito恕我直言的spring集成不是很好。 So, Could you help me to chose good Mock Framework with good integration with Spring ? 那么,您能否帮助我选择与Spring集成良好的Mock框架? Thanks. 谢谢。

What is wrong with Springockito ? 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 依赖项: org.kubek2k:springockito-annotations:1.0.9

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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