Spring Boot CLI - Testing Application


Advertisements


Let's test the sample project created in Hello World Example Chapter to demonstrate the testing capabilities of Spring CLI. Follow the below mentioned step to test the sample project −

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 TutorialsPoint.Com"
   }
} 

FirstApplication/TestFirstApplication.groovy

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

Run the application

Type the following command −

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

Now Spring Boot CLI will come into action, download required dependencies, compile the source and test file and unit test the code. You can see the following output on console −

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

OK (1 test)

Points to consider

Following actions are taken by Spring CLI −

  • @Test annotation directs CLI to download JUnit 4.12 version.

  • Spring CLI automatically detects the version using its metadata as we've not specified any dependency.

  • Finally it compiles the code, test the application



Advertisements
E-Books Store