Java程序中对Service进行Mock
背景
在项目中往往需要对service逻辑进行单元测试验证,这里采用mockito对dao数据进行模拟,验证service逻辑
Servie
package com.xx.kdc.service;
import com.xx.kdc.dao.codegen.TestMapper;
import com.xx.kdc.model.codegen.Test;
import com.xx.kdc.model.codegen.TestExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class TestService {
@Autowired
private TestMapper testMapper;
public Long save(Test test){
testMapper.insert(test);
return test.getId();
}
public void delete(Long id){
testMapper.deleteByPrimaryKey(id);
}
public Test getById(Long id){
return testMapper.selectByPrimaryKey(id);
}
public List<Test>