我有一个Spring项目。它可以通过Junit测试用例正常工作。Junit调用applicationcontext.xml文件,项目可以成功运行。但是我想不使用Junit来运行这个项目。
以下是我的Junit测试用例:
package com.dataload;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.util.StopWatch;
@ContextConfiguration(locations = "classpath:com/dataload/applicationcontext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class SICSVDataTestCase {
private final static Logger logger = Logger
.getLogger(SICSVDataTestCase.class);
@Autowired
private JobLauncher launcher;
@Autowired
private Job job;
private JobParameters jobParameters = new JobParameters();
@Test
public void testLaunchJob() throws Exception {
StopWatch sw = new StopWatch();
sw.start();
launcher.run(job, jobParameters);
sw.stop();
logger.info(">>> TIME ELAPSED:" + sw.prettyPrint());
}
}
这个测试用例运行了项目。但是我想使用另一个类来调用applicationcontext.xml并运行该项目。
也就是说,
package com.dataload;
public class insertCSV
{
public static void main(String args[])
{
/* Code to run the project */
}
}
有人能向我提供如何编程的建议吗?谢谢
@Test
注释的方法都将被执行。您也可以运行特定的测试方法。但在主函数中,您必须调用需要运行的方法。 - Anubhab