I’m looking for direction on how to test that a dynamically generated image is the expected image with JUnit. A bit of background: I have code that generates thumbnail images as java.awt.image.BufferedImage’s and stores those BufferedImages into a java.io.File object. I wrote a simple unit test to check a few key items in order to gain confidence that the generated
Tag: unit-testing
How to generate test-output folder from testng tests?
How to generate the test-output folder for a testNG test? I am trying to get the default testng report, index.html Netbeans7/windows7 I made a simple testng test case, ran it in netbeans 7, and here is the result. I see no test-output. I am displaying the project and file structure. If I need to do something with ant or maven,
Can anyone tell me how to test my Camel Route if I have a choice operation?
I have a Camel route that has implemented a Content based Routing EIP(Choice operation). I need to test it. I’m new to Camel. So, I’m unsure how to do it. Can anyone tell me how to test this operation. I have mentioned a sample code below that has to be tested. Answer You can simply “advice” your route and add
Mockito NotaMockException
I am facing an issue with Mockito junit testing. I am new to it and am a bit confused with the problem I am facing. Any help on this would be appreciated. Getting exception : in the below code I am aware that activity is not a mock but I am not sure for a way around this as secondMethod()
mock instance is null after @Mock annotation
I try to run this test: but I get NullPointerException for: Mockito.when(routingClientMock. what am i missing? Answer When you want to use the @Mock annotation you should use the MockitoJUnitRunner See also this tutorial.
How to write a unit test for a Spring Boot Controller endpoint
I have a sample Spring Boot app with the following Boot main class Controller What’s the easiest way to write a unit test for the controller? I tried the following but it complains about failing to autowire WebApplicationContext Answer Spring MVC offers a standaloneSetup that supports testing relatively simple controllers, without the need of context. Build a MockMvc by registering
Can we create a mocked instance of java.lang.Class with PowerMock?
I need to write a test that mocks a instance of the java.lang.Class class. Is this possible via PowerMock? I tried to do following: And the result is: According to the documentation of PowerMock this should be possible but still I get this error. Did someone manage to do this? Edit: Why do I need this? In the tested coding
Access a private field for a junit test
I am trying to initialize a private field from a class in order to unit test its methods. For that I am using reflection but I am always getting an IllegalArgumentException and I don’t understand what I am doing wrong. My code looks something like this: I get this error when I am trying to run the test: I also
jOOQ: Mocking DAO objects
jOOQ 3.5.0 I’m currently trying to write unit tests for a resource that is using jOOQs generated DAO objects. I’ve noticed one of the base classes (DAOImpl) in the DAO hierarchy has many final methods which makes it unfriendly to mock (I’m excluding byte code manipulators like Powermock as a solution). I’m currently using the MockConnection and MockDataProvider pattern to
Unit testing a class with a Java 8 Clock
Java 8 introduced java.time.Clock which can be used as an argument to many other java.time objects, allowing you to inject a real or fake clock into them. For example, I know you can create a Clock.fixed() and then call Instant.now(clock) and it will return the fixed Instant you provided. This sounds perfect for unit testing! However, I’m having trouble figuring