Skip to content
Advertisement

Tag: junit

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

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

How do I disable Java assertions for a junit test in the code

How do I disable java assertions (not junit assert) for a junit test in the code Ive written a junit test but when I run it it doesnt fail as expected because assertions are enabled, whereas they are not in production. Is there a way to disable assertions just in the code so that it work as expected when run

How to get the path of src/test/resources directory in JUnit?

I know I can load a file from src/test/resources with: But how can I get the full path to the src/test/resources directory, i.e. I don’t want to load a file, I just want to know the path of the directory? Answer Try working with the ClassLoader class: A ClassLoader is responsible for loading in classes. Every class has a reference

Spring junit tests with couchbase

I have some Services that should get documents from couchbase. Services: Also I have DocRepository interface with necessary methods and views on couchbase server. When I run my app and call Services its work fine, but I need tests for this Services. Tests: Running tests successful only in 90%. And another moment, I use maven, and when it runs tests

Is org.junit.Assert.assertThat better than org.hamcrest.MatcherAssert.assertThat?

I’m new to JUnit and Hamcrest and would like best-practice advice so I can decided which documentation to study first. For starters, which of these assertThat methods is better? org.junit.Assert.assertThat (from junit-4.11.jar) org.hamcrest.MatcherAssert.assertThat (from hamcrest-core-1.3.jar) According to one person last year, “JUnit has the assertThat method, but hamcrest has its own assertThat method that does the same thing.”. According to

Advertisement