一 业务层测试
在test下建立一个和main方法中同样层级的service包,在service包下新建测试类
package com.service;
import com.config.SpringConfig;
import com.domain.Book;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class BookServiceTest {
@Autowired
private BookService bookService;
@Test
public void testGetById(){
Book book= bookService.getById(1);
System.out.println(book);
}
}
第二步 controller测试,这个就是利用postman软件按照之前的步骤就行
第三步 在Springconfig下加这个
![](https://img-blog.csdnimg.cn/61c8ede2cbcb4556b6ab92bf07abe50b.png)