【java – 测试可完成的未来总是通过】教程文章相关的互联网学习教程文章

java – 关于URLConnection的JUnit测试,使用EasyMock?【代码】

嘿,在最后一天左右一直试图解决这个问题但是碰到了砖墙.试图对这段代码进行单元测试.但不确定是否需要使用EasyMock?在网上看似很少的例子,但似乎是使用旧技术.public boolean verifyConnection(final String url) {boolean result;final int timeout = getConnectionTimeout();if (timeout < 0) {log.info("No need to verify connection to client. Supplied timeout = {}", timeout);result = true;} else {try {log.debug("URL...

java – 带有TestNg的Maven-surefire-plugin:如何指定存储测试套件xml文件的目录?【代码】

我目前正在开发Maven支持的项目.我选择了TestNg来实现我的单一测试.为了在每个Maven构建中运行我的单一测试,我已经将maven-surefire-plugin添加到我的pom.xml:<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.12</version><configuration><!-- Configuring the test suites to execute --><suiteXmlFiles><suiteXmlFile>testsuite-persistence-layer.xml</suiteXm...

java – 使用gradle自定义JUnit测试检测【代码】

我们的测试套件正在快速增长,我们已经达到了功能测试依赖于其他系统的程度. 我们使用gradle测试任务来使用包含和排除过滤器来运行这些测试,但这变得很麻烦,因为我们必须以特定方式命名我们的测试. 我们目前的方法是以下列方式命名我们的测试:class AppleSingleServiceTest {} class BananaMultiServiceTest {} class KiwiIntegrationTest {}然后在相关任务中包含测试include '**/*SingleServiceTest.class' include '**/*MultiSer...

java – JUnit.并行运行.但所有测试方法都处理单例实例.怎么解决?

所以,我有几个JUnit类,每个类都包含一个测试方法列表.每种方法都是相互独立的,没有直接的联系.但我们有间接连接:所有方法都处理一个单独的对象(它是Selenium Web驱动程序实例,是的,我使用1个Web驱动程序实例进行所有测试,因为为了制作新的对象实例,我们花了很多时间!). 当测试方法在一个线程中逐步执行时,一切都好.但它太长了, 所以,我决定提高速度,怎么样? – 我决定在并行模式下运行所有??测试方法.为此,我使用具有特殊配置的...

java – 我应该为每个公共方法编写单元测试吗?

我应该为每种公共方法编写单元测试吗?例如,我有一个CRUD服务,所以我有创建,读取,更新,删除方法.但是当我编写测试来删除或更新方法时,我会隐式地测试读取和创建方法(例如,首先测试更新方法我需要创建一个实体(创建),然后检索它(读取),然后更新它然后检索它再次确保它改变了).解决方法:我会为get和create编写测试,是的: >它可以更容易地将您故意测试的行为与您偶然测试的行为分开>它可以更轻松地测试故障条件以及其他方法未涵盖的其...

java – 在集成测试中使用实时端点与使用模拟端点

最近我和我的同事一直在为Java项目编写集成测试.大多数这些集成测试需要至少一个SOAP Web服务调用,LDAP查询或其他依赖于我们不一定能控制的端点的东西.其中一些SOAP / LDAP调用使用的lib仍处于开发阶段. 这最终意味着我们的集成测试有时会在构建过程中失败,当机器出现故障,lib发生变化或端点被更改时.在做了一些研究后,我注意到人们在集成测试中使用实时端点似乎相当普遍,但我也发现了有关为什么使用实时端点可能有害的文章(http:/...

java – Spring JUnit测试【代码】

我喜欢测试我的弹簧代码:@ContextConfiguration(locations = { "/applicationContext.xml" }) @Transactional() public class Test {@AutowiredMyDao dao;@org.junit.Test@Rollback(false)public void testSomething() throws Exception {MyEntity e = new MyEntity();dao.create(e);} }使用eclipse运行此测试(作为JUNIT测试)只会产生Nullpointer-Exception. 我做错了什么?谢谢!解决方法:只需将@RunWith(SpringJUnit4ClassRunne...

java – 在另一个项目中重用Spring测试上下文【代码】

我有两个Java项目,“A”和“B”,B对A有Maven依赖:<dependency><!-- Back end stuff --><groupId>com.myapp</groupId><artifactId>ProjectA</artifactId><version>1.0.0</version> </dependency>这两个项目在我的工作站上并排放置在一个公共父文件夹中:/Myproject/ProjectA/ProjectB我想在Project B中对我的所有单元测试使用Project A的单元测试上下文“test-context.xml”.有没有办法直接引用外部上下文进行测试?这些是使用Sur...

java – 单元测试中的IncompatibleClassChangeError异常导致CXF失败【代码】

我有一个使用Spring-3.2.X和cxf-2.7.5的应用程序 我正在将cxf导入到我的spring的应用程序上下文中,如下所示:<import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:cxf.xml" />但是,当我运行测试时,我最终会遇到以下异常:java.lang.IllegalStateException: Failed to load ApplicationContextat org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextL...

java – Spring:为什么在每个测试类的末尾没有调用@PreDestroy?【代码】

我有一个集成测试类,注释如下@WebAppConfiguration @ContextConfiguration(classes = {AppConfiguration.class}) @RunWith(SpringJUnit4ClassRunner.class) public class CacheConsumerTest {}这是我的AppConfiguration@Configuration @ComponentScan(basePackages = {"com.etc.etc.etc."}) @EnableWebMvc public class AppConfiguration { }出于某种原因,在CacheConsumerTest中的所有测试结束时都没有调用我的@Component ...

java – SonarQube不显示单元测试结果【代码】

我有“TEST – *.xml”格式的JUnit测试报告,我正在尝试使用Ant将这些报告上传到SonarQube.我在build.xml文件中添加了以下属性,其中${reports.dir}计算到报告目录路径:<property name="sonar.dynamicAnalysis" value="reuseReports"/> <property name="sonar.junit.reportsPath" value="${reports.dir}"/>以下是Ant任务的输出(某些信息已编辑):sonar: [sonar:sonar] Apache Ant(TM) version 1.9.3 compiled on December 23 2013...

java – Spring测试:如何将配置默认配置为@AnnotationDriven?【代码】

目前我的课看起来像@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = {DemographicAttributesManager.class}) public class DemographicAttributesManagerTest {@Autowiredprivate DemographicAttributesManager demographicAttributesManager;@Testpublic void testGetGenders() throws Exception {final Map<Integer, String> genders = demographicAtt...

java – 运行Gradle测试时出现管道错误【代码】

关于在gradle中运行测试我遇到了问题.我知道在其他机器上我的gradle配置可以正常工作但不幸的是在我的机器上.我们有junit test和testNG,当他们尝试执行时,它们都会产生这样的堆栈跟踪:Could not write standard input into: Gradle Worker 1. java.io.IOException: The pipe is being closedat java.io.FileOutputStream.writeBytes(Native Method)at java.io.FileOutputStream.write(FileOutputStream.java:318)at java.io.Buffe...

为什么JUnit测试不能在Play 2.3.1 / Java项目中运行?【代码】

在我全新的Play 2.3.1 Java应用程序中,我编写了第一个测试,但它们根本不起作用.我启动了激活器测试,一个简单的测试类直接放在测试目录中的默认包中未到达.import org.junit.Assert; import org.junit.Test;public class TestTest {@Testpublic void testTest() {Assert.assertEquals(true, false);} }当我启动activator testOnly TestTest时,我有以下输出:[info] Passed: Total 0, Failed 0, Errors 0, Passed 0 [info] No tests ...

java – Handler.handleMessage未在测试中调用,但在应用程序中调用【代码】

我有一个在单独进程中运行的服务.该服务在onCreate()方法中生成一个新线程.该线程将消息发送回服务. 如果我手动启动应用程序一切正常 – 处理程序在我的服务中收到消息.但在我的测试中,handleMessage()方法永远不会被调用. 如何修复我的测试以使handleMessage()方法有效? 谢谢! 服务:public class MyService extends Service {private ServiceHandler mHandler;private final int MSG_HELLO_WORLD = 1;private final String TAG...