0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Spring Bootを基本からまとめてみた【テスト】

Last updated at Posted at 2025-12-09

テストクラスの命名規則

①対象のテストのわかりやすさ
②Marvenのテスト実行時の挙動

**/Test*.java
**/*Test.java
**/*Tests.java
**/*TestCase.java

Marven(ビルドツール)はデフォルトで上記のクラス名をテストクラスとして認識する

PartsA.java
package testclass;

import org.springframework.stereotype.Component;

@Component
public class PartsA {

    public String getText() {
        return "Hello artsA";
    }
}
PartsATest.java
package testclass;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class PartsATest {

    // テストクラス
    PartsA partsA = new PartsA();

    @Test
    public void testGetText() {

        // テスト対象メソッドの呼び出し
        String returnValue = targetClass.getText();
        // 戻り値検証
        assertEquals("Hello artsA", returnValue);
    }
}

参考サイト

第6回 テストの仕組み編【誰もが一度はつまずくSpring Bootを解説♪】【若手Javaエンジニア向け】

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?