junit

MockMVC in junit tests - checking result for List<Object> and Map<Enum, Object>

Deadly 提交于 2020-08-27 07:51:29
问题 I have problems with mockMVC and test written with that. My tests fails. I have two tests methods: @Test public void getPersonsForApiConsumerTest() throws Exception { mockMvc.perform(get(getUri("/consumers/1/persons"))) .andExpect(status().isOk()) .andExpect(jsonPath("$", hasSize(2))) .andExpect(jsonPath("$[1].name", is("Ligza"))) .andExpect(jsonPath("$[2].name", is("Vekrir"))); } @Test public void getPersonsForApiConsumerMapTest() throws Exception { mockMvc.perform(get(getUri("/consumers/1

Is the 'IT.java' filename Suffix (instead of 'Test.java') for JUnit Integration Tests a convention? [closed]

雨燕双飞 提交于 2020-08-27 05:36:27
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Improve this question I was used to naming my JUnit Integration tests with a *Test.java on the end eg DatabaseConnectionTest.java and placing them in their own integration test directory: eg test/integration/com... On joining a new project I was directed No, all the Tests go

Why my JUnit error collector is not reporting the error?

萝らか妹 提交于 2020-08-26 10:12:28
问题 I am trying to report error using JUnit error collector. Although my assertion is failing, error is not reported in JUnit. But I am getting the "error" message in console. @Rule public ErrorCollector errcol = new ErrorCollector(); @Then("^Business alert message on the screen$") public void Business_alert_message_on_the_screen(Result_Update) throws Throwable { if (userType.equals("Admin")) { try { Assert.assertEquals("Update button is not present for the admin user", true, Result_Update); }

How to test if @Valid annotation is working?

落花浮王杯 提交于 2020-08-24 11:27:40
问题 I have the following unit test: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {EqualblogApplication.class}) @WebAppConfiguration @TestPropertySource("classpath:application-test.properties") public class PostServiceTest { // ... @Test(expected = ConstraintViolationException.class) public void testInvalidTitle() { postService.save(new Post()); // no title } } The code for save in PostService is: public Post save(@Valid Post post) { return postRepository.save

How to test if @Valid annotation is working?

ぃ、小莉子 提交于 2020-08-24 11:26:32
问题 I have the following unit test: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {EqualblogApplication.class}) @WebAppConfiguration @TestPropertySource("classpath:application-test.properties") public class PostServiceTest { // ... @Test(expected = ConstraintViolationException.class) public void testInvalidTitle() { postService.save(new Post()); // no title } } The code for save in PostService is: public Post save(@Valid Post post) { return postRepository.save

Mock a method that returns a Stream and is called more than one time

眉间皱痕 提交于 2020-08-24 07:29:07
问题 MyStreamClass mock = mock(MyStreamClass.class); when(mock.streamMethod()).thenReturn(Stream.of("A", "B")); System.out.println(""+mock.streamMethod().findFirst()); System.out.println(""+mock.streamMethod().findFirst()); the second call of findFirst will throw java.lang.IllegalStateException: stream has already been operated upon or closed 回答1: Try the thenAnswer instead of thenReturn : Answer<Stream> answer = new Answer<Stream>() { public Stream answer(InvocationOnMock invocation) throws

Spring H2 Test DB does not reset before each test

不想你离开。 提交于 2020-08-22 06:25:38
问题 EDIT: As C. Weber suggested in the comments, the solution is to add @Transactional to the test class. I have some tests that use an H2 in-memory DB. I need to reset the DB before each test. Although my SQL scripts are run each a test is executed, the DB is not properly reset, resulting in a missing needed entry after a delete test. Test class: @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureTestDatabase(replace=Replace.ANY, connection=EmbeddedDatabaseConnection.H2) public class

TypeNotPresentExceptionProxy

五迷三道 提交于 2020-08-21 07:01:39
问题 When upgrading from Surefire 2.6 to Surefire 2.13, I get a TypeNotPresentExceptionProxy when running my unit tests. java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:653) at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:460) at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:286) at sun.reflect.annotation.AnnotationParser

测试常备知识和技能

非 Y 不嫁゛ 提交于 2020-08-19 19:08:46
测试具体工作 搭建测试环境 撰写测试用例 执行测试用例 写测试计划,测试报告 测试,并提交BUG表单 跟踪bug修改情况 执行自动化测试,编写脚本,执行,分析,报告 进行性能测试,压力测试等其他测试,执行,分析,调优,报告 测试一般流程 需求分析 测试计划 测试设计 测试执行 测试评估 测试总结 产品维护 产品业务知识 所测产品功能 所测产品用户场景 安全测试方法 测试相关技能 业务分析能力,分析整体业务流程、分析被测业务数据、分析被测系统架构、分析被测业务模块、分析测试所需资源、分析测试完成目标; 掌握测试基本流程、常规用例设计方法; 管理、软件质量评估能力; 常用测试工具:TestLink、PostMan、BugZilla、仪表等; 测试框架:JUnit、RobotFramework等; 自动化测试知识; 简单项目管理知识; 编程语言基础:shell、Python、Java、C/C++、Mysql/Sqllite等; 计算机基础知识,Linux、计算机网络等; 软件测试基础理论知识,如黑盒测试、白盒测试等。 测试类型 功能 性能 可靠性 易用性 兼容性 可维护性 安全性 可移植性 测试常用方法 (1)黑盒测试 黑盒测试也称功能测试或数据驱动测试,它是在已知产品所应具有的功能,通过测试来检测每个功能是否都能正常使用,在测试时,把程序看作一个不能打开的黑盆子