草庐IT

junit-ee

全部标签

spring - Java EE 和 Spring 框架的区别

关闭。这个问题需要更多focused.它目前不接受答案。想要改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭9年前。Improvethisquestion我正在努力了解JavaEE和SpringFramework之间的区别。谁能帮我解决这个问题。 最佳答案 JavaEE是功能齐全的企业应用程序框架堆栈的标准、官方规范。包括对象关系映射、安全性、Web应用程序、数据库连接、事务......除了JavaEE规范之外,还有JavaEE实现/应用服务器,例如:JBoss、Glassfish、WebSphere

java - 如何使用 Spring 为 JUnit 测试注入(inject) ServletContext?

我想对使用ApacheCXF编写的RESTful接口(interface)进行单元测试。我使用ServletContext来加载一些资源,所以我有:@ContextprivateServletContextservletContext;如果我将它部署在Glassfish上,则会注入(inject)ServletContext并且它会像预期的那样工作。但我不知道如何在我的服务类中注入(inject)ServletContext,以便我可以使用JUnit测试对其进行测试。我使用Spring3.0、JUnit4、CXF2.2.3和Maven。 最佳答案

java - j2ee Web 应用程序的标准项目/包结构

我们正在使用Spring、SpingMVC和Hibernate启动一个新的JavaEEWeb应用程序。我们很可能也会使用maven。在开始之前,我们需要为Web应用程序提出项目/包结构。JavaEEWeb应用程序的标准项目/包结构是什么?它还应该在所有应用程序服务器上运行,而无需对项目结构或任何配置文件进行任何更改。我们将使用Spring源IDE版本2.6.0(最新版本)。有什么想法吗? 最佳答案 如果您使用的是maven,最好遵循标准的maven项目布局。你可以让maven为你生成这个结构,mvnarchetype:generat

hibernate - Spring/Hibernate/JUnit - 没有绑定(bind)到线程的 hibernate session

我正在尝试访问测试用例中的当前hibernatesession,并收到以下错误:org.hibernate.HibernateException:NoHibernateSessionboundtothread,andconfigurationdoesnotallowcreationofnon-transactionalonehereatorg.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)atorg.hibernate.impl.Sessio

java - 为 JUnit Runner (Eclipse) 设置系统属性以测试 Spring Web App

我们的网络应用使用SystemPropertyPlaceholder根据系统属性的值加载属性文件(见下文)在本地运行它的默认设置存储在application.properties中。在生产服务器上,我们目前只是在部署应用程序之前将“env”设置为“production”,它将加载production.properties。现在为了测试应用程序,应该使用test.properties文件。如果我运行我们的jenkins构建中的所有测试,添加-Denv=test将按预期工作。但是,如果我只想使用集成的JUnit运行器在Eclipse中运行单个测试呢?@RunWith(SpringJUnit

spring - 为什么我收到 MockMvc 和 JUnit 的错误 403?

我有一个带有springsecurity(3.2)的springmvc(3.2.5)应用程序。我用这个方法配置了我的SecurityConfig.class:@Overrideprotectedvoidconfigure(HttpSecurityhttp)throwsException{http.authorizeRequests().antMatchers("/*").permitAll().and().formLogin().successHandler(successHandler).defaultSuccessUrl("/").failureHandler(failureHan

java - @TestPropertySource 不适用于 Spring 1.2.6 中使用 AnnotationConfigContextLoader 的 JUnit 测试

似乎我在Spring4.1.17中使用SpringBoot1.2.6.RELEASE所做的任何事情都不起作用。我只想访问应用程序属性并在必要时用测试覆盖它们(不使用黑客手动注入(inject)PropertySource)这不起作用..@TestPropertySource(properties={"elastic.index=test_index"})这个也不行..@TestPropertySource(locations="/classpath:document.properties")也不是这个..@PropertySource("classpath:/document.prop

spring - Junit测试Spring服务和DAO层

我正在开发一个Spring应用程序(Spring3.0)并遵循分层架构,即Controller->Service->DAO层。我想使用Junit为服务和DAO层编写单元测试用例。我查看了Spring官方网站并尝试了许多其他网站,但无法找到一种简单易行的方法。谁能给我一些有用的资源?编辑:看起来像Mockito是不错的选择。在Spring中使用它的任何好的链接。感谢Alex的建议。MockingHibernateDAO 最佳答案 在资源方面,Spring的测试文档非常好。这可以找到here.当您测试服务层时,您将需要使用Mockito

java - 如何在 Spring Boot JUnit 测试中排除 *AutoConfiguration 类?

我试过了:@RunWith(SpringJUnit4ClassRunner.class)@EnableAutoConfiguration(exclude=CrshAutoConfiguration.class)@SpringApplicationConfiguration(classes=Application.class)@WebAppConfigurationpublicclassLikeControllerTest{但是,CRaSSHD仍然启动。虽然目前它不会损害测试,但我想在单元测试期间禁用不必要的模块以加快速度并避免潜在的冲突。 最佳答案

java - 如何使用参数化运行 JUnit SpringJUnit4ClassRunner?

由于重复的@RunWith注解,以下代码无效:@RunWith(SpringJUnit4ClassRunner.class)@RunWith(Parameterized.class)@SpringApplicationConfiguration(classes={ApplicationConfigTest.class})publicclassServiceTest{}但是如何结合使用这两个注解呢? 最佳答案 您可以使用SpringClassRule和SpringMethodRule-Spring提供importorg.junit.C