基于ssh的项目的单元测试

package com.csoft.ta.util;

import java.io.File;

import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;

/**
* abstract class for test
* @author hason.xie
*
*
*/
public abstract class AbsBaseTest extends AbstractTransactionalDataSourceSpringContextTests {

@Override
protected String[] getConfigLocations() {
File directory = new File("");//设定为当前文件夹
String path= directory.getAbsolutePath();

//using ClassPathXmlApplicationContext instead of FileSystemXmlApplicationContext i guess, Hanson
String[] config = new String[] { "file:"+path+"\\WebContent\\WEB-INF\\applicationContext.xml"};
return config;
}

}

package com.csoft.ta.fuzzymatch;

import static org.junit.Assert.*;

import org.junit.Test;
import org.springframework.test.annotation.Rollback;

import com.csoft.ta.db.po.Tmmain;
import com.csoft.ta.db.po.Tmtmp;
import com.csoft.ta.util.AbsBaseTest;
import com.csoft.ta.util.Constant;

public class FMEngineTest extends AbsBaseTest{

@Rollback(false)
@Test
public void testInsertTmtmpandIndex() {
//fail("Not yet implemented");
FMEngine fmEngine= (FMEngine)applicationContext.getBean("fmEngine");
Tmtmp tmtmp= new Tmtmp();
//tmtmp.setId(3692);
tmtmp.setSt_langpair(87);
tmtmp.setSource("I am a student of college, you are a teacher of university");
tmtmp.setTmStatus(Constant.TM_STATUS_1);
tmtmp.setProjectlangpairfileId(54);
try {
fmEngine.insertTmtmpandIndex(tmtmp);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Rollback(false)
@Test
public void testInsertTmmainandIndex() {
//fail("Not yet implemented");
FMEngine fmEngine= (FMEngine)applicationContext.getBean("fmEngine");
Tmmain tmmain= new Tmmain();
//tmmain.setId(3692);
tmmain.setClientid(1);
tmmain.setStLangpair(87);

tmmain.setSource("I am a student of college, you are a teacher of university");
tmmain.setTarget("我是学院的学生,你是大学老师");
try {
fmEngine.insertTmmainandIndex(tmmain);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

猜你喜欢

转载自smartzjp.iteye.com/blog/1615582