Junit测试单元
This commit is contained in:
parent
0bf8068778
commit
fd72129e4e
44
src/test/java/com/example/springdemo/ControllerTests.java
Normal file
44
src/test/java/com/example/springdemo/ControllerTests.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user