1、XML引用添加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2、添加junit启动类
package com.xxxxxx.tams.batch.test;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.xxxxxx.tams.batch.TamsBatchApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TamsBatchApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ApplicationTests {
/**
* 日志
*/
private Logger logger = LoggerFactory.getLogger(getClass());
@Before
public void init() {
// System.out.println("开始测试-----------------");
logger.info("开始测试-----------------");
}
@After
public void after() {
// System.out.println("测试结束-----------------");
logger.info("测试结束-----------------");
}
}
3、添加test类
package com.XXXXXXX.tams.batch.service;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class serviceTest extends ApplicationTests{
/**
* 日志
*/
private static Logger logger = LoggerFactory.getLogger(MonthReportCBProdServiceTest.class);
@Autowired
private MainService MainService;
@Test
public void testGenReport() throws Exception{
Date executeDate = null;
Date endDate = null;
List<String> prodIdList=new ArrayList<String>();
prodIdList.add("Test001");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
executeDate= sdf.parse("2019-11-01");
endDate= sdf.parse("2019-07-05");
}
catch (ParseException e) {
// e.printStackTrace();
logger.error(e.getMessage(),e);
}
MainService.generateInvestTradeData(executeDate,null,false);
while(executeDate.compareTo(endDate)<=0){
executeDate=DateUtil.addDay(executeDate, 1);
}
}
}
4、在test类运行juint test即可