Finding import static statements for Mockito constructs

后端 未结 3 1853
醉梦人生
醉梦人生 2021-01-30 10:05

I\'m trying to crash through the brick wall between me and Mockito. I\'ve torn my hair out over trying to get correct import static statements for Mockito stuff. You\'d

3条回答
  •  时光取名叫无心
    2021-01-30 10:27

    Here's what I've been doing to cope with the situation.

    I use global imports on a new test class.

    import static org.junit.Assert.*;
    import static org.mockito.Mockito.*;
    import static org.mockito.Matchers.*;
    

    When you are finished writing your test and need to commit, you just CTRL+SHIFT+O to organize the packages. For example, you may just be left with:

    import static org.mockito.Mockito.doThrow;
    import static org.mockito.Mockito.mock;
    import static org.mockito.Mockito.verify;
    import static org.mockito.Mockito.when;
    import static org.mockito.Matchers.anyString;
    

    This allows you to code away without getting 'stuck' trying to find the correct package to import.

提交回复
热议问题