Live TemplateにJUnitで使うあれこれを追加しました!
できたこと
↓Tabをおすと、Templateが入力される!
設定のしかた
Setting > Live Templates
+ボタンを押して、「1.Live Template」を選択。
基本的には↑の赤枠で囲った部分を設定していく。
Abbreviation:templateを呼び出すときに使用する文字列
Description:templateの説明
Template text:ここで設定したものが展開される
Define:ここで、どの状況でTemplateを開くかを設定できる
設定したテンプレートたち
テストメソッド
Abbreviation:test
Description:JUnit test method
Define:Java > Declaration
Template text:
@org.junit.Test public void _$should_assert_a_behaviour$() throws Exception { // Setup // Exercise // Verify }
インスタンスメソッドのテスト
Abbreviation:instantiation
Description:JUnit instantiation test
Define:Java > Declaration
Template text:
public static class インスタンス化テスト { @org.junit.Test public void デフォルトコンストラクタ() throws Exception { // Exercise $class$ instance = new $class$(); // Verify assertThat(instance, is(notNullValue())); } $END$ }
setUpメソッド
Abbreviation:setUp
Description:JUnit setUp method
Define:Java > Declaration
Template text:
@org.junit.Before public void setUp() throws Exception { // Setup $END$ }
setUpClassメソッド
Abbreviation:setUpClass
Description:JUnit setUpClass method
Define:Java > Declaration
Template text:
@org.junit.BeforeClass public static void setUpClass() throws Exception { // Setup $END$ }
tearDownメソッド
Abbreviation:tearDown
Description:JUnit tearDown method
Define:Java > Declaration
Template text:
@org.junit.After public void tearDown() throws Exception { // After $END$ }
tearDownClassメソッド
Abbreviation:tearDownClass
Description:JUnit tearDownClass method
Define:Java > Declaration
Template text:
@org.junit.AfterClass public static void tearDownClass() throws Exception { // After $END$ }
whenメソッド
Abbreviation:when
Description:JUnit context test class
Define:Java > Declaration
Template text:
public static class _$test_context$の場合 { $END$ }
assertThat
Abbreviation:at
Description:JUnit Assertion
Define:Java > Statement
もろもろ設定方法は、↓を参照してやりました!
IntelliJ IDEAでJavaのstatic import文に関する効率化設定をLive Templateで実現する(しおしお版) - しおしおの雑記帳
参考
下記サイトを参考にしました!ありがとうございます!
Intellij IDEAにJUnitのLive templateを追加する。 - Qiita
IntelliJ IDEAでJavaのstatic import文に関する効率化設定をLive Templateで実現する(しおしお版) - しおしおの雑記帳
ちなみに、インポートしたLive Templateの種類とDescriptionは、
↓の本の付録とサンプルコードに同封されていたeclipseプラグインの設定を見て決めました。
JUnit実践入門 ~体系的に学ぶユニットテストの技法 (WEB+DB PRESS plus)
- 作者: 渡辺修司
- 出版社/メーカー: 技術評論社
- 発売日: 2012/11/21
- メディア: 単行本(ソフトカバー)
- 購入: 14人 クリック: 273回
- この商品を含むブログ (67件) を見る
はかどるー☆