当前位置: 首页 > news >正文

公众平台微信公众号官网湖南企业seo优化首选

公众平台微信公众号官网,湖南企业seo优化首选,软件开发文档通用要求,软文代理平台在Internet上寻找一种测试我的Spring 3应用程序的方法#xff0c;我找到了许多描述如何使用JUnit测试应用程序的文章。 它们中的大多数都是不完整的示例#xff0c;实际上并不起作用。 在这篇文章中#xff0c;我将尝试填补这一空白#xff0c;并撰写一篇简洁而简单的文章我找到了许多描述如何使用JUnit测试应用程序的文章。 它们中的大多数都是不完整的示例实际上并不起作用。 在这篇文章中我将尝试填补这一空白并撰写一篇简洁而简单的文章介绍如何使用Junit 4测试spring 3应用程序。Ta使其更易于阅读和遍历我不会使用现在很大的应用程序但我将使用viralpatel提供的样本。 下载项目的链接是这里 。 下载此应用程序并将其导入eclipse。 在您的数据库中执行以下命令 create database contact; use contact; CREATE TABLE CONTACTS (id INT PRIMARY KEY AUTO_INCREMENT,firstname VARCHAR(30),lastname VARCHAR(30),telephone VARCHAR(15),email VARCHAR(30),created TIMESTAMP DEFAULT NOW() ); 在pom.xml中添加以下依赖项 dependencygroupIdorg.springframework.data/groupIdartifactIdspring-data-jpa/artifactIdversion1.0.1.RELEASE/version /dependency dependencygroupIdorg.junit/groupIdartifactIdcom.springsource.org.junit/artifactIdversion4.7.0/versionscopetest/scope /dependency dependencygroupIdorg.springframework/groupIdartifactIdorg.springframework.test/artifactIdversion${org.springframework.version}/versionscopetest/scope /dependency dependency groupIdjavax.transaction/groupIdartifactIdcom.springsource.javax.transaction/artifactIdversion1.1.0/version /dependency 还为存储库添加以下内容 repositoriesrepositoryidcom.springsource.repository.bundles.release/idnameSpringSource Enterprise Bundle Repository - SpringSource Releases/nameurlhttp://repository.springsource.com/maven/bundles/release/url/repositoryrepositoryidcom.springsource.repository.bundles.external/idnameSpringSource Enterprise Bundle Repository - External Releases/nameurlhttp://repository.springsource.com/maven/bundles/external/url/repositoryrepositoryidcom.springsource.repository.bundles.milestone/idnameSpringSource Enterprise Bundle Repository - SpringSource Milestones/nameurlhttp://repository.springsource.com/maven/bundles/milestone/url/repositoryrepositoryidcom.springsource.repository.bundles.snapshot/idnameSpringSource Enterprise Bundle Repository - Snapshot Releases/nameurlhttp://repository.springsource.com/maven/bundles/snapshot/url/repositoryrepositoryidrepository.springframework.maven.release/idnameSpring Framework Maven Release Repository/nameurlhttp://maven.springframework.org/release/url/repositoryrepositoryidrepository.springframework.maven.milestone/idnameSpring Framework Maven Milestone Repository/nameurlhttp://maven.springframework.org/milestone/url/repositoryrepositoryidrepository.springframework.maven.snapshot/idnameSpring Framework Maven Snapshot Repository/nameurlhttp://maven.springframework.org/snapshot/url/repositoryrepositoryidjboss/idnameJBoss repository/nameurlhttps://repository.jboss.org/nexus/content/repositories/releases/url/repository /repositories 在目录src / test / java下创建以下软件包 net.viralpatel.contact.form 在刚创建的包中创建一个名为 抽象接触测试 在src / test / resources下创建以下内容 净/ viralpatel /联系人/表格 在其中创建以下文件 AbstractContactTests-context.xml 注意 确保目录软件包类和xml文件的创建位置与上述位置完全相同。 您将看到xml文件使用测试类的名称加上“ -context.xml”并且该文件是在相同目录结构下创建的。 这很重要因为spring会自动在指定目录下查找具有指定名称的xml文件。 现在在AbstractContactTests类中插入以下内容 package net.viralpatel.contact.form;import net.viralpatel.contact.dao.ContactDAO; import net.viralpatel.contact.service.ContactService; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;ContextConfiguration public class AbstractContactTests extends AbstractTransactionalJUnit4SpringContextTests {Autowiredprotected ContactDAO contact;Autowiredprotected ContactService contactService;Testpublic void sampleTest(){System.out.println(Number of rows is: contactService.listContact().size());System.out.println(Creating a new contact);Contact cont new Contact();cont.setEmail(giannisgmail.com);cont.setLastname(ntantis);cont.setFirstname(ioannis);cont.setTelephone(00306985587996);System.out.println(Before saving contact);contactService.addContact(cont);System.out.println(After saving contact. Id if contact is: cont.getId());System.out.println(Number of rows now is: contactService.listContact().size());} } ContextConfiguration注释告诉spring如何加载和配置应用程序上下文。 我们还可以告诉spring在哪里可以找到文件例如 ContextConfigurationlocations {“ example / test-context.xml”}loader CustomContextLoader.class 通过不提供任何参数spring将在与类包相同的目录下查找xml文件并在名为class.name-context.xml的文件中查找记住上面的提示。 请注意我们的类从org.springframework.test.context.junit4扩展了AbstractTransactionalJUnit4SpringContextTests 。 通过扩展此类我们在类级别为方法提供了事务支持。 如果我们不这样做我们需要事务支持则必须使用Transactional注释方法或者使用TransactionConfiguration注释配置事务管理器。 在AbstractContactTests-context.xml中放入以下内容 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beans xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:contexthttp://www.springframework.org/schema/contextxmlns:jdbchttp://www.springframework.org/schema/jdbcxmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsdcontext:property-placeholder locationclasspath:jdbc.properties/context:annotation-config/tx:annotation-driven/bean iddataSource classorg.apache.commons.dbcp.BasicDataSource destroy-methodclosep:driverClassNamecom.mysql.jdbc.Driver p:urljdbc:mysql://localhost:3306/contactp:usernameroot p:password123456/bean idsessionFactoryclassorg.springframework.orm.hibernate3.LocalSessionFactoryBeanproperty namedataSource refdataSource /property nameconfigLocationvalueclasspath:hibernate.cfg.xml/value/propertyproperty nameconfigurationClassvalueorg.hibernate.cfg.AnnotationConfiguration/value/propertyproperty namehibernatePropertiespropsprop keyhibernate.dialect${jdbc.dialect}/propprop keyhibernate.show_sqltrue/prop/props/property/beanbean idtransactionManager classorg.springframework.orm.hibernate3.HibernateTransactionManagerproperty namesessionFactory refsessionFactory //beanbean idcontactDAO classnet.viralpatel.contact.dao.ContactDAOImpl/beanbean idcontactService classnet.viralpatel.contact.service.ContactServiceImpl/bean /beans 在这里您将看到spring-servlet.xml中定义的许多定义。 在我的示例中它们与spring-servlet.xml相同但是您可以随意更改它们。 这样Spring就有机会为测试过程创建不同的数据源甚至为每个测试类创建不同的数据源。 现在执行AbstractContactTests类作为junit测试。 您应该获得以下输出 Hibernate: select contact0_.ID as ID0_, contact0_.EMAIL as EMAIL0_, contact0_.FIRSTNAME as FIRSTNAME0_, contact0_.LASTNAME as LASTNAME0_, contact0_.TELEPHONE as TELEPHONE0_ from CONTACTS contact0_ Number of rows is: 0 Creating a new contact Before saving contact Hibernate: insert into CONTACTS (EMAIL, FIRSTNAME, LASTNAME, TELEPHONE) values (?, ?, ?, ?) After saving contact. Id if contact is: 2 Hibernate: select contact0_.ID as ID0_, contact0_.EMAIL as EMAIL0_, contact0_.FIRSTNAME as FIRSTNAME0_, contact0_.LASTNAME as LASTNAME0_, contact0_.TELEPHONE as TELEPHONE0_ from CONTACTS contact0_ Number of rows now is: 1 多数民众赞成在所有您需要的人。 祝您编程愉快别忘了分享 参考 使用JUnit 4进行Spring 3测试。使用来自Giannisapi博客的 JCG合作伙伴 Ioannis Ntantis的ContextConfiguration和AbstractTransactionalJUnit4SpringContextTests 。 相关文章 JUnit 4.9测试版3中的规则 单元和集成测试的代码覆盖率 Spring MVC3 Hibernate CRUD示例应用程序 将Jersey与Spring整合 SpringQuartz和JavaMail集成教程 Spring声明式事务示例 Java教程和Android教程列表 翻译自: https://www.javacodegeeks.com/2011/10/spring-3-testing-with-junit-4.html
http://www.huolong8.cn/news/221194/

相关文章:

  • 网站建设学院平面设计比较好的网站
  • ppt 做的最好的网站有哪些西安百度网站快速优化
  • 网站主机教程ppt网站建设
  • 网站根目录验证文件网页版小红书
  • 网站建设常见问题处理建设银行手机网站首页
  • 旅游网站建设目标网站建设岗位工作范围
  • 城乡建设部官方网站网站开发公司广告文案
  • 文山州住房建设网站外国人做的关于中国的视频网站
  • 大丰网站制作网站到期是否能换服务商
  • 网站建设前景展望wordpress教程dara
  • 优化前网站现状分析做网站的软件 简单易学
  • 网站页面数量同一虚拟空间做两个网站
  • win8网站模版卓训网是个什么网站
  • 家里电脑如何做网站影视网站建设多少钱
  • 济南seo外贸网站建设徐州住房与城乡建设部网站
  • 做网站还要买服务器吗行业网站大全
  • 网站做浮动边框asp代码宜昌恒大帝景二手房
  • 一级a做爰片免费网站 新闻wordpress 单页面 外贸
  • 网站设计软件晋江+网站建设+推广
  • 网页设计的五大原则正规seo关键词排名哪家专业
  • 棋牌室的网站怎么做家具定制十大名牌
  • 万江专业网站快速排名网站建设高端设计
  • 用电脑建设个人网站 并用手机访问推广网站建设产品介绍
  • 做理财网站网站建设技术团队有多重要
  • seo技术大师安康地seo
  • 南冒网站建设制作推广公司dedeseo网站
  • 制作英文网站多少钱网页制作与网站建设 论文
  • 学校特色网站建设情况蓝白清爽企业通用wordpress模板
  • 青岛崂山区网站建设2015做哪些网站能致富
  • 免费做网站的软件wordpress微信免签能用吗