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

java-Spring Boot单元测试-测试失败,抱怨没有定义“ entityManagerFactory” bean【代码】

我正在尝试在Spring Boot应用程序中为Controller编写单元测试.该应用程序运行平稳,我的问题是运行其测试. 这是测试代码:@RunWith(SpringRunner.class) @WebMvcTest(MyController.class) @AutoConfigureTestEntityManager public class MyControllerTest {@Autowired private MockMvc mockMvc;@Mock private MyRepository myRepository;@Mock ZendeskNotifier zendeskNotifier;@Mock ActivityLogger activityLogger;@Before public...

在JavaDoc中包括指向(单元)测试类的链接

在类的JavaDoc中包括(单元)测试类的链接是一种好习惯还是一种好习惯? 到目前为止,我还没有看到它,但是发现它在上课和测试课之间跳转时非常有帮助.我还认为测试用例为使用类提供了很好的例子. 在JavaDoc中反对链接测试用例的论点是什么?解决方法:绝对不是好习惯. 出于一个简单的原因:生产代码的责任在于其“生产工作”.生产代码不负责提供有关测试设置的信息!有时,有一种受程序包保护的方法很实用,该方法允许您检查对象的内部状...

java-junit5-并行运行测试(在pom中没有forkCount)【代码】

为了并行执行我的JUnit测试,我使用了提供的解决方案here(感谢@peanut和@Reid Mac).这对于JUnit 4效果很好,但是我正尝试从JUnit 4迁移到JUnit5.由于JUnit 5测试是由直接扩展Runner的JUnitPlatform执行的,因此JUnit 5无法实现等效功能.JUnit 5是否具有任何类似的方法setScheduler?以下是我的代码段. JUnit4Runner.classimport java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotati...

春季-JUnit测试使用java.lang.Exception引发了InitializationError:找不到匹配的测试【代码】

运行JUnit测试时,它给出了初始化错误:找不到匹配的测试.像这样:prodapi-main-junit initializationError(org.junit.runner.manipulation.Filter) java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testCreateSite], {ExactMatcher:fDisplayName=testCreateSite(com.company.product.api.web.rest.HostControllerTest)], {LeadingIdentifierMatcher:fClassName=com.company.product.api.web.rest.HostC...

java-JUnit 5 Surefire Maven:如何为动态Web模块项目运行测试?【代码】

“ mvn测试”会编译我的测试用例,但不会运行它:[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-server --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to my-server\backend\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ my-server --- [INFO] [INFO] -----------------------------------------------...

java-每个位置具有不同属性的Springboot测试【代码】

简而言之,我的问题是:如何在不同的环境中运行具有不同属性的测试? 长版:我写了一个JUnit-Test,它在类顶部带有注释,如下所示:@RunWith(SpringRunner.class) @SpringBootTest( classes=RunServer.class, webEnvironment = WebEnvironment.DEFINED_PORT ) @TestPropertySource(locations="file:conf/application-junit.properties") public class MyDbTest {...在当前的conf / application.junit.properties中,有端口5400上的数据...

Mockito测试Java 8 Lambda Consumer API【代码】

我需要使用lambda Consumer测试使用另一个接口作为依赖项注入的calss.@Builder public class Interactor {private final Gateway gateway;void process(String message, Consumer<String> response){gateway.process(message, uuid -> {response.accept(uuid.toString());});} }依赖关系的定义如下:public interface Gateway {void process(String message, Consumer<UUID> uuid); }我将如何模拟网关,以便为测试提供UUID值响应? ...

java-在竞争的使用者队列上侦听的多个测试应用程序上下文会导致间歇性测试失败【代码】

我有一个正在测试的JMSInboundGateway,它侦听Apache Artemis队列(竞争使用者).我的测试将消息发送到Artemis服务器,并模拟目标服务.如果调用了模拟服务,那么我已经验证了JmsInboundGateway的设置正确. 流程如下所示:测试发件人-> Artemis Queue-> JmsInboundGateway-> DirectChannel-> ServiceActivator->模拟(目的地服务) 如果测试是JUnit测试套件中唯一运行的测试类,则它会像冠军一样运行.但是,如果套件中还有其他测试类,则测试将...

java-SpringBoot和GitLab CI运行测试【代码】

我只想使用GitLab CI来运行测试,而不是部署我的应用程序.我设法组装这个.yml文件:image: java:8stages:- build- testbuild:stage: buildscript: ./gradlew buildartifacts:paths:- build/libs/myApp-4.0.0-SNAPSHOT.jarunitTests:stage: testscript:- ./gradlew test在GitLab管道中,出现以下错误:ar.com.sebasira.myApp.myAppApplicationTests > contextLoads FAILEDjava.lang.IllegalStateExceptionCaused by: org.springframew...

将Java Mockito测试转换为Kotlin【代码】

将以下有效的Java测试转换为Kotlin时遇到问题@Test public void testSomething() {Mockito.when(parkIdMappingRepository.save(Mockito.any(ParkIdMapping.class))).thenAnswer((Answer<ParkIdMapping>) invocation -> {ParkIdMapping mapping = invocation.getArgument(0);mapping.setId(100L);return mapping;});ParkIdMapping mapping = parkIdMappingRepository.save(new ParkIdMapping("123"));assertEquals(new Long(100L), ...

java-使用JUnit 5和Spring Boot 2.0.0进行的嵌套测试【代码】

我正在尝试为我正在构建的应用程序编写一些嵌套的集成测试. 测试是相互叠加的,应该测试整个工作流程是否按预期进行. 我尝试这样做,如下所示:@RunWith(SpringRunner.class) @SpringBootTest @ExtendWith(SpringExtension.class) public class XMLTest {@BeforeAllpublic void setUp() {// Initialize some things}@Nested@DisplayName("testA")class testA {@Testpublic void testGettingSomething() {... test something ...}@Nes...

对于Java测试,我应该模拟客户端还是模拟服务器

在客户端-服务器体系结构中,当一个人应该模拟客户端并且什么时候应该模拟服务器时,最好的方法应该是什么.我知道单元测试应该只测试给定的类,并且模拟每个依赖对象,而集成测试应该测试整个功能.当涉及到API调用时,我不知道应该模拟用于api调用的客户端还是应该使用某些服务器模拟框架并让真正的客户端调用模拟服务器. 我遇到一种情况,我应该(不是强制性的)测试是否命中了正确的API URL,正确的方法以及在查询参数或请求正文中传递的某...

java-如何将@WebMvcTest用于单元测试POST方法?【代码】

我正在使用Spring Boot和Mockito运行单元测试,并且正在测试RESTful服务.当我尝试测试GET方法时,它可以成功运行,但是当我尝试测试POST方法时,则失败.我应该怎么做才能解决这个问题?提前致谢! 这是REST控制器的代码:package com.dgs.restfultesting.controller;import java.net.URI; import java.util.List;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; imp...

java-在Spring集成测试期间刷新/重建特定的bean【代码】

我们现有的Spring Boot集成设置使用@DirtiesContext在不同的测试方法之间重建整个bean池. 这是相当慢的,所以我们开始使用可以“刷新”或在内部拆除/重建的Bean,而无需重新创建实例. 问题是只有一些bean支持此功能.如果我们控制UsersBean,则可以实现UsersBean.refresh()方法并在我们的@After方法中调用它. 但是,如果我们有不支持刷新或无法控制的现有bean /类,我们如何有条件地指示在特定测试后需要对某些bean进行污染/重建? 或更简...

java-使用Jacoco和Circle CI生成测试覆盖率失败【代码】

我正在尝试使用此文件config.yml在Circle CI中生成测试覆盖率,但是构建失败,并且显示无连接的设备.以下是在Circle CI上生成的错误:而且据我了解,Circle CI目前不支持仿真器. 以下是我的config.yml文件:version: 2 jobs:build:working_directory: ~/ConvergeLevelAppdocker:- image: circleci/android:api-25-alphaenvironment:JVM_OPTS: -Xmx3200mCC_TEST_REPORTER_ID: 403xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxADB_INSTALL_TIMEOUT:...