标签: integration-testing

Gradle:如何在控制台中显示androidTest结果?

如其他线程中所述,可以将Gradle配置为将测试结果记录到控制台中:

基本上,这可以通过以下任务设置:

tasks.withType(Test) {
    testLogging {
       // Custom configuration
    }
}
Run Code Online (Sandbox Code Playgroud)

这适用于单元测试,看起来有点像这样:

...
:app:assembleDebugUnitTest
:app:testDebugUnitTest
:app:processDebugResources

com.example.StringsTest > formatValue PASSED
com.example.StringsTest > formatValueWithDecimals FAILED

1 test completed, 1 failed
Run Code Online (Sandbox Code Playgroud)

此外,单元测试我也使用以下命令运行集成测试:

$ ./gradlew connectedAndroidTest
Run Code Online (Sandbox Code Playgroud)

当我查看控制台中的输出时,我错过了为单元测试编写的单个测试结果.如何为仪器测试配置测试日志记录?

android integration-testing gradle android-testing

24
推荐指数
2
解决办法
2167
查看次数

spring-data-rest集成测试因简单的json请求而失败

我的spring-data-rest集成测试因简单的json请求而失败.考虑下面的jpa模型

Order.java

public class Order {

    @Id @GeneratedValue//
    private Long id;
    @ManyToOne(fetch = FetchType.LAZY)//
    private Person creator;
    private String type;

    public Order(Person creator) {
        this.creator = creator;
    }

    // getters and setters
}
Run Code Online (Sandbox Code Playgroud)

Person.java

ic class Person {

    @Id @GeneratedValue private Long id;

    @Description("A person's first name") //
    private String firstName;

    @Description("A person's last name") //
    private String lastName;

    @Description("A person's siblings") //
    @ManyToMany //
    private List<Person> siblings = new ArrayList<Person>();

    @ManyToOne //
    private Person father;

    @Description("Timestamp this person object …
Run Code Online (Sandbox Code Playgroud)

java integration-testing spring-data-jpa spring-data-rest spring-boot

24
推荐指数
2
解决办法
652
查看次数

在Maven中,是否可以将集成测试保存在单元测试的单独文件夹中?

Maven和Integration Testing页面上,它说:

Future Rumor认为,除了测试阶段的src/test/java之外,Maven的未来版本将在集成测试阶段支持src/it/java之类的东西.

但那是在2011-12-11.这件事发生了吗?

这个回答"不违约的src /测试/ java文件夹运行Maven测试"它提到设置<testSourceDirectory>,是他们这样做只是为了集成测试(即在某种方式integration-test相)?

我正在寻找使用Maven FailSafe插件,并避免重命名一堆集成测试或使用仍然实验性的JUnit @Categories.

integration-testing maven maven-failsafe-plugin

23
推荐指数
1
解决办法
6196
查看次数

集成测试的Spring Boot身份验证

我正在尝试为我的控制器运行集成测试,但如果我不进行身份验证,我会遇到问题.这是我的控制器:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {"security.basic.enabled=false", "management.security.enabled=false"})
@EnableAutoConfiguration(exclude = {org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class})
public class HelloControllerIT {
    private final ObjectMapper mapper = new ObjectMapper();
    @Autowired private TestRestTemplate template;

    @Test
    public void test1() throws Exception {
        ObjectNode loginRequest = mapper.createObjectNode();
        loginRequest.put("username","name");
        loginRequest.put("password","password");
        JsonNode loginResponse = template.postForObject("/authenticate", loginRequest.toString(), JsonNode.class);

        HttpHeaders headers = new HttpHeaders();
        headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
        headers.add("X-Authorization", "Bearer " + loginResponse.get("token").textValue());
        headers.add("Content-Type", "application/json");
        return new HttpEntity<>(null, headers);

        HttpEntity request = getRequestEntity();
        ResponseEntity response = template.exchange("/get",
                                                    HttpMethod.GET,
                                                    request,
                                                    new ParameterizedTypeReference<List<Foo>>() {});
        //assert stuff
    }
} …
Run Code Online (Sandbox Code Playgroud)

java authentication spring integration-testing spring-boot

23
推荐指数
2
解决办法
2万
查看次数

在数据库中创建测试数据

我知道那里有一些测试数据生成器,但大多数似乎只是填写名称和地址样式数据库[随意纠正我].

我们有一个大型的集成和标准化应用程序 - 例如,发票上有与库存表相关联的零件号,与客户表相关联的客户编号,与审计信息相关的更改日志等,这些都很难随机填写.目前,我们对实际数据进行模糊处理以获得测试数据(但不是很好).

您使用哪些工具\方法来创建要测试的大量数据?

database integration-testing

22
推荐指数
1
解决办法
2万
查看次数

如何在PHP中执行集成测试?

我目前正在对我的代码执行单元测试(使用PHPUnit和Jenkins),但我已经阅读了很多关于集成测试的内容.

  • 是否有任何工具可以在PHP(最好是自动化)中执行此操作?

  • 我将如何实施它?在任何地方都有任何好的教程吗?

php automation integration-testing

22
推荐指数
2
解决办法
1万
查看次数

如何让Capybara在Cucumber功能中执行DELETE请求?

我正在使用Cucumber和Capybara.我需要发出HTTP DELETE请求.以前使用webrat的功能,所以简单的声明就好

visit "/comment/" + comment_id, :delete
Run Code Online (Sandbox Code Playgroud)

工作,但现在我使用Capybara.

做一个GET请求的方法很简单:

get 'path'
Run Code Online (Sandbox Code Playgroud)

并做一个帖子请求:

page.driver.post 'path'
Run Code Online (Sandbox Code Playgroud)

但是我如何模拟DELETE请求呢?

我发现司机Capybara正在使用的是Capybara::RackTest::Driver,如果有任何帮助的话.

我也尝试过:

Capybara.current_session.driver.delete "/comments/" + comment_id
Run Code Online (Sandbox Code Playgroud)

但这不起作用.

integration-testing ruby-on-rails cucumber capybara

22
推荐指数
2
解决办法
7828
查看次数

我应该如何设置集成测试以将测试数据库与Entity Framework一起使用?

我正在为应用程序编写集成测试,并且无法找到有关如何为我的集成套件设置测试数据库的最佳实践.我正在使用实体框架代码优先处理ASP.NET MVC4应用程序.

我可以确认我的测试项目中的测试默认与我的机器上的本地开发数据库通信.这并不理想,因为我希望每次运行测试时都有一个新的数据库.

如何设置我的测试项目以便我的测试与单独的实例进行通信?我假设可以设置SQL Server Compact Edition实例,但我不知道如何配置它.

c# asp.net-mvc integration-testing entity-framework ef-code-first

22
推荐指数
3
解决办法
2万
查看次数

在应用程序启动之前配置@MockBean组件

我有一个Spring Boot 1.4.2应用程序.在启动期间使用的一些代码如下所示:

@Component 
class SystemTypeDetector{
    public enum SystemType{ TYPE_A, TYPE_B, TYPE_C }
    public SystemType getSystemType(){ return ... }
}

@Component 
public class SomeOtherComponent{
    @Autowired 
    private SystemTypeDetector systemTypeDetector;
    @PostConstruct 
    public void startup(){
        switch(systemTypeDetector.getSystemType()){   // <-- NPE here in test
        case TYPE_A: ...
        case TYPE_B: ...
        case TYPE_C: ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有一个组件可以确定系统类型.在从其他组件启动期间使用此组件.在生产中一切正常.

现在我想使用Spring 1.4的@MockBean添加一些集成测试.

测试看起来像这样:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyWebApplication.class, webEnvironment = RANDOM_PORT)
public class IntegrationTestNrOne {
    @MockBean 
    private SystemTypeDetector systemTypeDetectorMock;

    @Before 
    public void initMock(){
       Mockito.when(systemTypeDetectorMock.getSystemType()).thenReturn(TYPE_C);
    }

    @Test 
    public void testNrOne(){ …
Run Code Online (Sandbox Code Playgroud)

java spring integration-testing mocking spring-boot

22
推荐指数
3
解决办法
5286
查看次数

使用@WebMvcTest获取"必须至少存在一个JPA元模型"

我是Spring的新手,试图为a做一些基本的集成测试@Controller.

@RunWith(SpringRunner.class)
@WebMvcTest(DemoController.class)
public class DemoControllerIntegrationTests {
    @Autowired
    private MockMvc mvc;

    @MockBean
    private DemoService demoService;

    @Test
    public void index_shouldBeSuccessful() throws Exception {
        mvc.perform(get("/home").accept(MediaType.TEXT_HTML)).andExpect(status().isOk());
    }
}
Run Code Online (Sandbox Code Playgroud)

但我得到了

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!
Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

与发布此错误的大多数人不同,我不想为此使用JPA.我试图使用@WebMvcTest不正确吗?我怎样才能找到邀请JPA参加这个派对的Spring魔术呢?

java integration-testing spring-mvc spring-data-jpa spring-boot

22
推荐指数
3
解决办法
2万
查看次数