junit4

AssertEquals(String, String) ComparisonFailure when contents are identical

守給你的承諾、 提交于 2019-11-28 03:04:31
问题 I'm facing the following scenario: I have an app that spits everything out to the STDOUT (simple company test) and I'm trying to JUnit this. My problem is, when I run the application, it returns me in the Console: (copy and pasted from IntelliJ) Id 1234 nao encontrado 123, R$ 441,00 321, R$ -8490,00 255, R$ 884,00 Print: And my test is: assertEquals(outContent.toString().trim(),"Id 1234 nao encontrado\n" + "123, R$ 441,00\n" + "321, R$ -8490,00\n" + "255, R$ 884,00"); I'm getting: junit

What do I use instead of Whitebox in Mockito 2.2 to set fields?

一个人想着一个人 提交于 2019-11-28 02:34:57
问题 When using Mockito 1.9.x I have been using Whitebox to set values of fields to "inject" mocks. Se example below: @Before public void setUp() { eventHandler = new ProcessEventHandler(); securityService = new SecurityServiceMock(); registrationService = mock(RegistrationService.class); Whitebox.setInternalState(eventHandler, "registrationService", registrationService); Whitebox.setInternalState(eventHandler, "securityService", securityService); } I really like this approach, but now that I

Getting javassist.NotFoundException with PowerMock and PowerRule in JUnit with Mockito

只谈情不闲聊 提交于 2019-11-28 00:33:02
问题 I have integrated PowerMock and PowerRule in JUnit with Mockito. Here are my dependencies: <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.12.0.GA</version> </dependency> <dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>3.3.1</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>org.powermoc</groupId> <artifactId>powermock-module

Can Selenium take a screenshot on test failure with JUnit?

久未见 提交于 2019-11-27 23:31:20
When my test case fails, especially on our build server, I want to take a picture / screenshot of the screen to help me debug what happened later on. I know how to take a screenshot, but I was hoping for a way in JUnit to call my takeScreenshot() method if a test fails, before the browser is closed. No, I don't want to go edit our bazillions of tests to add a try/catch. I could maybe, just possibly be talked into an annotation, I suppose. All of my tests have a common parent class, but I can't think of anything I can do there to solve this. Ideas? Jeff Bowman A few quick searches led me to

Error creating bean with name defaultServletHandlerMapping

故事扮演 提交于 2019-11-27 22:52:28
I converted all my XML Spring configuration to Java code ones, but i am not getting able to run all my test (which they worked before) because i have an ugly exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]:

Apply '@Rule' after each '@Test' and before each '@After' in JUnit

爱⌒轻易说出口 提交于 2019-11-27 22:50:57
I have a test suite where I am logging out of the system in @After and closing the browser in @AfterClass . I am trying to use @Rule to take failed test screenshot using Selenium for every test method. I checked manually that @Rule only runs before every @Before but I want to set it up after @Test and before @After . I couldn't find out simple solution. Any help will be appreciated. public class MorgatgeCalculatorTest { @Before public void before(){ System.out.println("I am before"); } @BeforeClass public static void beforeclass(){ System.out.println("I am beforeclass"); } @Test public void

How to write JUnit test with Spring Autowire?

為{幸葍}努か 提交于 2019-11-27 22:45:48
Here are the files that I use: component.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee

Java unit test for different input data

不羁的心 提交于 2019-11-27 22:17:29
问题 I need to test some api. For example I have multiple @Test methods in the class to test my functionality, before init I connect to some url of my service, and use it. If I have my service at multiple urls(different server environments), how can I Test this functionality for different service urls? Flow: Init conncetion by url Run all Tests Init conncetion by another url Run all Tests(the same) ... when was only one host I do like this: public class TestAPI{ @org.junit.Before public void init(

Verify Static Method Call using PowerMockito 1.6

泪湿孤枕 提交于 2019-11-27 21:19:45
问题 I am writing JUnit test case for methods similar to sample given below: Class SampleA{ public static void methodA(){ boolean isSuccessful = methodB(); if(isSuccessful){ SampleB.methodC(); } } public static boolean methodB(){ //some logic return true; } } Class SampleB{ public static void methodC(){ return; } } I wrote the following test case in my test class: @Test public void testMethodA_1(){ PowerMockito.mockStatic(SampleA.class,SampleB.class); PowerMockito.when(SampleA.methodB())

Continuing test execution in junit4 even when one of the asserts fails

不问归期 提交于 2019-11-27 18:41:59
I have my existing framework built up using Jfunc which provides a facility to continue exection even when one of the asserts in the test case fails. Jfunc uses junit 3.x framework. But now we are migrating to junit4 so I can't use Jfunc anymore and have replaced it with junit 4.10 jar. Now the problem is since we have extensively used jfunc in our framework, and with junit 4 we want to make our code continue the execution even when one of the asserts fails in a test case. Does anyone has any suggestion/idea for this, i know in junit the tests needs to be more atomic i.e. one assert per test