POM.xml
4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.4.RELEASE com.example TestingTuto12 0.0.1-SNAPSHOT TestingTuto12 Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-devtools runtime org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
TestingTuto12Application
package com.example.testingtuto12;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestingTuto12Application {
public static void main(String[] args) {
SpringApplication.run(TestingTuto12Application.class, args);
}
}
GreetingController
package com.example.testingtuto12;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
@RequestMapping("/greeting")
public Boolean sendGreeting() {
return true;
}
}
TestingTuto12ApplicationTests
package com.example.testingtuto12;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestingTuto12ApplicationTests {
@Test
public void contextLoads() {
}
@Autowired
public GreetingController greetingController;
@Test
public void testSendGreeting() {
Boolean greeting = greetingController.sendGreeting();
//assertEquals(greeting, "Hello World Dude!");
assertTrue(greeting);
}
}
To run the test, right click the testSendGreeting() method and select run as JUnit test as shown below .
No comments:
Post a Comment