当前位置:首页 » 数据仓库 » soma如何配置
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

soma如何配置

发布时间: 2023-02-26 03:17:38

① 如何用Junit4测试Spring框架下配置的类

如何用Junit4测试Spring框架下配置的类


前几天,我们在做Junit4的单元测试时,遇到了问题,就是Junit无法获得spring的配置环境,即Junit无法得到Spring创建的类实例。
在查阅了网上的一些资料和同事的帮助下,成功的解决了此问题。步骤如下:
1 建立一个test的目录,在此目录下放置所有的JunitTestCase类和TestCase的配置文件
2 将项目中的Spring配置文件(默认名称为applicationContext.xml)复制到test目录下,并重新命名为JunitTestConf.xml。
3 根据Junit测试的需要修改JunitTestConf.xml文件中的内容,如数据库连接等。
4 新建一个名为SpringConfForTest.java的类,在此类中配置Spring启动所需的配置文件,并启动Spring。此类的内容如下:
package test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.;
import com.soma.global.WebContextHolder;
public class SpringConfForTest {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
//Spring启动所需要的配置参数文件,其中test/JunitTestConf.xml文件中保存了数据库连接等参数,可根据具体情况做修改
String[] paths = new String[] {"test/JunitTestConf.xml", "com/soma/conf/applicationContext--hr.xml","com/soma/conf/applicationContext-.xml","com/soma/conf/applicationContext--bug.xml","com/soma/conf/applicationContext--change.xml","com/soma/conf/applicationContext--common.xml","com/soma/conf/applicationContext-service-hr.xml" };
//启动Spring,得到Spring环境上下文
ApplicationContext ctx = new (paths);
//在此类启动时,将Spring环境上下文保存到单根类WebContextHolder中,以提供给其它的测试类使用
WebContextHolder.getInstence().setApplicationContext(ctx);
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Test
public void test(){
//必须要写一个test空方法,否则SpringConfForTest类不会启动
}
}
5 新建TestSuite类,类名为AllTests,类的内容如下所示:
package test;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import test.com.soma.domain.busilogic.hr.HrBusiLogicTest;
import test.com.soma.domain.service.hr.checkOverTimeDateTest;
@RunWith(Suite.class)
@Suite.SuiteClasses({
SpringConfForTest.class,
HrBusiLogicTest.class,
checkOverTimeDateTest.class
})
/**
* 批量执行Junit测试类,把类名写入到上面的Suite.SuiteClasses({})中,用逗号分隔
*/
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for test");
//$JUnit-BEGIN$
//$JUnit-END$
return suite;
}
}
注意:将SpringConfForTest.class放在第一个执行,以启动Spring配置环境,把自己的TestCase类放到后面,用逗号分开。在测试时,只要执行这个TestSuite类就可以了。
6 写自己的TestCase类,以CheckOverTimeDateTest.java为例子,文件内容如下:
public class CheckOverTimeDateTest {
private static HrTbovertimeManager hrTbovertimeManager;
private static ExcuteSqlDAO excuteSqlDAO;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
//从Spring上下文中得到hrTbovertimeManager接口类的实例
hrTbovertimeManager=(HrTbovertimeManager)BeanUtil.getBean("hrTbovertimeManager");
excuteSqlDAO = (ExcuteSqlDAO) BeanUtil.getBean("excuteSqlDAO");
}
@Test
public void testGetProjectList()throws Exception {

List<OvertimeDetailValue> overtimeDetailValueList = new ArrayList<OvertimeDetailValue>();
int index = 9;
for(int i = 1 ;i <= index;i++){
OvertimeDetailValue overtimeDetailValue = new OvertimeDetailValue();
overtimeDetailValue.setOtApplyDate("2009-05-0"+i);
overtimeDetailValueList.add(overtimeDetailValue);
}
String resultStr = hrTbovertimeManager.checkOverTimeDate(overtimeDetailValueList);
assertEquals("false", resultStr);
}
/**
* 导入2009-03月份出勤记录excel文件,返回null表示导入成功,需要先删除3月份的数据
*/
@Test
public void testSaveExcelDutyInformation() throws Exception{
// 在导入3月份出勤记录前先删除3月份的记录,执行delete from hr_tbtyinformation;
excuteSqlDAO.excuteSql("delete from hr_tbtyinformation where tydate>='2009-02-26' and tydate<='2009-03-25'");
// System.out.println("----------"+System.getProperty("user.dir")+"/src/test/ty200903.xls");
String fileName = System.getProperty("user.dir")
+ "/src/test/ty200903.xls";
assertNull(hrTbtyInformationManager.saveExcelDutyInformation(fileName));
}
}
说明:BeanUtil.getBean("")相当于WebContextHolder.getInstence().getApplicationContext().getBean(""),只是对此方法做了封装。
7 在Eclipse中,启动AllTests,选择“Run As JunitTest”,即可先启动Spring环境,再依次运行你自己所写的JunitTestCase

② vscode 与 webstorm 各自有什么优缺点

vscode优点:

该编辑器也集成了所有一款现代编辑器所应该具备的特性,包括语法高亮(syntax high lighting),可定制的热键绑定(customizable keyboard bindings),括号匹配(bracket matching)以及代码片段收集(snippets)。

Somasegar 也告诉笔者这款编辑器也拥有对 Git 的开箱即用的支持。Microsoft Docs(微软文档)提供了相应的学习教程帮助用户在 Visual Studio Code 中登陆 GitHub。

缺点:要开发大型项目要下很多插件,配置很多,如ESLint配置,prettier配置等等,2021年了,点击CSS类名跳转、CSS类名提示仍需要借助插件,而且vue中无法跳转class和id。

代码提示缺失AI,官方的AI插件不是很好用。重构文件名没有自动更新功能,git相比webstorm真是一言难尽。不过解决冲突很强。

webstorm优点:

如官方描述一样,功能碾压所有前端开发工具。向官方反馈问题马上能得到回应,可以去twitter上看看它的回复。

缺点:正版中文不如VSCode友好,要翻译就希望认真翻译,太多机翻的东西了。wsl开发不是很爽(慢)。