Questions tagged [spring-junit]

67 questions
3
votes
1 answer

@After method being run first by JUnit

I am running into a strange issue with my JUnit test case: the @After method is invoked first by JUnit. Here is the abstract class I use for my test: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {…
balteo
  • 23,602
  • 63
  • 219
  • 412
2
votes
3 answers

SpringBoot: Running a Junit unit test with minimal configuration

Im having a Springboot project where I have found a way to create and run simple Junit testcase which looks into a repository and fetches some data attribute for a given entity. The result of the Junit run is pass so no problem in regards to that.…
Erfan Tavoosi
  • 389
  • 5
  • 16
2
votes
1 answer

How to disable auto test run while building jar file in Spring boot application?

I have created spring boot application for all my repositories&entities. I need to disable the auto test run while building jar file because these repositories points to different databases. Can anyone please help me here ? Thanks.
Krish
  • 1,804
  • 7
  • 37
  • 65
2
votes
0 answers

Unable to set multiple expectation with MockWebServiceServer

I am using a MockWebServiceServer to test the REST APIs. I am passing the values to it using @Runwith(Parameterized.class). @RunWith(Parameterized.class) public class MyAPITest { protected static MockWebServiceServer mockServer; …
rupesh
  • 413
  • 9
  • 19
2
votes
1 answer

"org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same" when running Spring Integration Test

I am running into a strange issue, for which I am not sure what is the best way to solve the problem. I wrote some JPA entity classes which get persisted into the Database just fine, however when I run in a Spring JUnit environment, I get the…
Seagull
  • 2,219
  • 6
  • 25
  • 33
2
votes
1 answer

How to test Dao with Dbunit for table which is not having hibernate entity

I have wrote a test class for Dao using DbUnit and dataset Here is my class : @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:config/appContext-test.xml"…
Pracheer Pancholi
  • 570
  • 2
  • 7
  • 21
2
votes
1 answer

Spring integration errorChannel no messages in JUnit

I have a simple JUnit test in which I am testing errorChannel by hooking up a service activator. However, nothing comes to this channel the config is as follows,
ameet chaubal
  • 1,440
  • 16
  • 37
2
votes
0 answers

SpringJUnitRunner based tests fail under PIT

I have a project that utilizes SpringJUnitRunner for testing the controllers and filters. When I run the test normally, everything runs fine. However, when I run the tests with PIT I get the following exception for every test using the…
Jesse
  • 83
  • 1
  • 6
1
vote
1 answer

unable to mock the resttemplate call using restclienttest

I want to mock my RestTemplate which uses RestTemplateBuilder. Hence, I am using restclienttest. Unfortunately, I am not able to mock the resttemplate call. when Sup supExpected = myService.getDetails("1234") is called, it's performing the complete…
Manju
  • 21
  • 2
1
vote
1 answer

How can i check if each object in an array has a specific property exists using spring junit integration test?

I am writing a spring integration test for a method in my resource class . accessing the resource method returns a json response . I would like do an assertion . the following is my test method. @Test public void…
1
vote
0 answers

How to programmatically Autowire a bean based on Qualifier Annotation

In Junit5, when using Extensions, we can run BeforeAll and AfterAll methods, and I'm trying to change behaviour of the test using Annotations. However, I'm using these annotations as @Qualifiers as well for bean initialisation, and want to be able…
nishantvas
  • 184
  • 3
  • 16
1
vote
1 answer

Spring boot Failed to load applicationcontext

Have a springboot application which reads files from source directory using file-inbound-adapter.Written junit testcases for it. Junit testcase execute successfully in my local eclipse. but facing issue while running it from bamboo/jenkins which is…
1
vote
2 answers

@SpringBootTest - failed to load applicationcontext

Test class: @RunWith(SpringRunner.class) @SpringBootTest public class FileInterfaceTest { @Test public void contextLoads() { } } Application : AppConfig: @Configuration @ImportResource({ "classpath:process-flows.xml" }) public…
1
vote
1 answer

Client authorization not working for unit tests

Okay, so first thing that's important to know here is that I can use the actual web client as intended. I am able to register a user and login with it. However, as I try to implement some unit tests, things are not working for me. This is how I am…
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
1
vote
2 answers

junit no webapplication context found: no ContextLoad Listener registered?

I am trying to write test cases for my structs application in which some of configurations in springs based xml files. i moved all my applicationContext files into src/test/resources class path but when i run my test class(RunAs-> Junit Test), it…
Viswanathan
  • 73
  • 1
  • 1
  • 6