そこに仁義はあるのか(仮)

略してそこ仁!

Intellij IDEAのLive TemplateにJUnitで使う、あれこれを追加した!

Live TemplateにJUnitで使うあれこれを追加しました!

できたこと

f:id:syobochim:20140423003933p:plain

↓Tabをおすと、Templateが入力される!

f:id:syobochim:20140423003953p:plain

設定のしかた


Setting > Live Templates
+ボタンを押して、「1.Live Template」を選択。

f:id:syobochim:20140423004811p:plain
基本的には↑の赤枠で囲った部分を設定していく。

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)

JUnit実践入門 ~体系的に学ぶユニットテストの技法 (WEB+DB PRESS plus)


はかどるー☆

2014/04/28 追記



みてみた

f:id:syobochim:20140428200940p:plain
えらんだ


f:id:syobochim:20140428201007p:plain
なんかでた


f:id:syobochim:20140428201025p:plain

…………。

Intellij IDEAやっぱりかしこいでつね(^p^)

しおしおさん、教えていただいてありがとうございます!