Junit测试单元

This commit is contained in:
myh 2023-11-11 20:08:35 +08:00
parent 0bf8068778
commit fd72129e4e
2 changed files with 53 additions and 4 deletions

View File

@ -0,0 +1,44 @@
package com.example.springdemo;
import com.example.springdemo.controller.MerchantsController;
import com.example.springdemo.controller.UsersController;
import com.example.springdemo.service.MerchantsService;
import com.example.springdemo.service.UsersService;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
@WebMvcTest(UsersController.class)
class UsersControllerTests {
@Resource
private UsersController usersController;
@MockBean
private UsersService usersService;
@Test
public void contextLoads() {
// Test that the controller loads
assert usersController != null;
// Test that the service loads
assert usersService != null;
}
}
@WebMvcTest(MerchantsController.class)
class MerchantsControllerTests {
@Resource
private MerchantsController merchantsController;
@MockBean
private MerchantsService merchantsService;
@Test
public void contextLoads() {
// Test that the controller loads
assert merchantsController != null;
// Test that the service loads
assert merchantsService != null;
}
}

View File

@ -1,13 +1,18 @@
package com.example.springdemo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SpringDemoApplicationTests {
public class SpringDemoApplicationTests {
@Test
void test(String[] args) {
SpringApplication.run(SpringDemoApplication.class, args);
}
@Test
void contextLoads() {
}
@Test
void contextLoads() {
}
}