Skip to content
Advertisement

Tag: unit-testing

Testing image files with JUnit

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

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,

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()

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

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

Advertisement