Skip to content

Instantly share code, notes, and snippets.

@donchan922
Created June 1, 2019 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donchan922/d6a7c005dc95134efe30d17b2401ffe1 to your computer and use it in GitHub Desktop.
Save donchan922/d6a7c005dc95134efe30d17b2401ffe1 to your computer and use it in GitHub Desktop.
class DemoControllerTest {
private MockMvc mockMvc;
// テスト対象のクラス内で呼び出すクラス(依存クラス)をモック化する
@Mock
private DemoService demoService;
// テスト対象のクラスにモックをインジェクションする
@InjectMocks
private DemoController demoController;
@BeforeEach
void setup() {
// 各テストの実行前にモックオブジェクトを初期化する
MockitoAnnotations.initMocks(this);
this.mockMvc = MockMvcBuilders.standaloneSetup(demoController).build();
}
@Test
void GETでアクセスする() throws Exception {
// テスト内容
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment