Springbootcli-testing-application

提供:Dev Guides
移動先:案内検索

Spring Boot CLI-テストアプリケーション

この章では、link:/springbootcli/springbootcli_hello_world [Hello Worldの例]の章で作成したサンプルプロジェクトをテストして、Spring CLIのテスト機能を示します。 サンプルプロジェクトをテストするには、以下の表に記載されている手順に従ってください-

Sr.No Step & Description
1 Create FirstApplication.groovy and TestFirstApplication.groovy in Test folder as explained below.
2 Compile and run the application to verify the result of the implemented logic.

FirstApplication/FirstApplication.groovy

@RestController
class FirstApplication {
   @RequestMapping("/")

   String welcome() {
      "Welcome to finddevguides.Com"
   }
}

FirstApplication/TestFirstApplication.groovy

class TestFirstApplication {
   @Test
   void welcomeTest() {
      assertEquals("Welcome to finddevguides.Com", new FirstApplication().welcome())
   }
}

アプリケーションを実行する

アプリケーションを実行するには、次のコマンドを入力します-

E:/Test/FirstApplication/> spring test FirstApplication.groovy TestFirstApplication.groovy

これで、Spring Boot CLIが実行され、必要な依存関係がダウンロードされ、ソースとテストファイルがコンパイルされ、コードがユニットテストされます。 次の出力がコンソールに生成されます-

Resolving dependencies........................................................
.
Time: 0.457

OK (1 test)

重要なポイント

次の点を考慮して、Spring CLIで実行されるアクションを理解します-

  • @Testアノテーションは、CLIにJUnit 4.12バージョンをダウンロードするよう指示します。
  • Spring CLIは依存関係を指定していないため、メタデータを使用してバージョンを自動的に検出します。
  • 最後に、コードのコンパイル後、アプリケーションをテストします。