Questions tagged [springjunit4classrunner]

55 questions
96
votes
13 answers

Disable @EnableScheduling on Spring Tests

When I run my unit tests, it invokes my scheduled tasks. I want to prevent this behaviour, which is caused by the fact that I have @EnableScheduling on my main app configuration. How can I disable this on my unit tests? I have come across this…
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
26
votes
3 answers

How to test multiple Spring Boot applications in one test?

I have a multi-module Maven project with 2 Spring Boot applications parent fooApp barApp test How to set up a test where you can load separate spring boot applications, each with its own configuration context, in the same process. public…
14
votes
7 answers

The import org.springframework.test.context.junit4.SpringJUnit4ClassRunner cannot be resolved

I'm a newbie at Spring and this is also my very first question on StackOverflow so I'm going to try to make this as understandable as possible. I'm trying to make a web service client using Spring and Maven on this tutorial: and I get this error:…
Juan Carlos
  • 187
  • 1
  • 1
  • 13
12
votes
1 answer

Why the cryptic MultipleFailureException error message with the SpringJUnit4ClassRunner.withAfterClasses method

Why is my spring test set up failing with the following not-so-useful error messages below? All suggestions are appreciated. JUnit Output java.lang.NoClassDefFoundError: org/junit/runners/model/MultipleFailureException at…
Stephen Isienyi
  • 1,292
  • 3
  • 17
  • 29
8
votes
2 answers

why properties from appliction.properties not available in Junit test in spring boot application?

I have a spring boot application. I am writing Junit tests. I am trying to inject values from application.properties (defined in src/main/resources/application.properties) and a Status bean configured in AppConfig…
brain storm
  • 30,124
  • 69
  • 225
  • 393
8
votes
1 answer

"Address already in use: bind" exception when running Gradle JUnit tests

I'm using Spring Boot 1.2.1.RELEASE, JUnit4, and Gradle 2.1 for a RESTful service and am trying to define a properties file which includes and/or overrides values which will be used in JUnit tests only. All tests execute without an issue when…
ethesx
  • 1,339
  • 5
  • 19
  • 35
4
votes
3 answers

Cannot run powermockrule with SpringJUnit4ClassRunner in spring boot project

I have a spring boot project that needs to test with spring test runner(so that I can get the real application context) and mock the static method. @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes=…
snowery
  • 468
  • 1
  • 6
  • 18
3
votes
1 answer

Pre loading data from .sql before unit testing throws syntax error

I'm performing unit testing on spring boot app using JPA and SpringJUnit4ClassRunner. for that I have created a configuration file as - @Configuration @EnableJpaRepositories(basePackages = "base_package_name") @EnableTransactionManagement public…
3
votes
0 answers

Could not open JDBC Connection for transaction in Spring Junits

Spring junits are getting failed during the maven build. If I run each test case individually it is working fine. If I run in bulk then only I am getting the below error. Spring version is 4.3.0 and Junit version is 4.12 Exception: WARNING:…
sidhartha pani
  • 623
  • 2
  • 12
  • 23
3
votes
2 answers

@RunWith(SpringJUnit4ClassRunner.class) Can not load an ApplicationContext with a NULL 'contextLoader'

I hava this code , @RunWith(SpringJUnit4ClassRunner.class) public class JunitDemo { @Test public void testAssertArrayEquals() { byte[] expected = "trial".getBytes(); byte[] actual = "trial".getBytes(); …
dai
  • 1,025
  • 2
  • 13
  • 33
3
votes
1 answer

initializationError running junit test with SpringJUnit4ClassRunner after moving or deleting a class

Often, when I move or delete a Class, I got an initializationError running junit test with SpringJUnit4ClassRunner after moving or deleting a class. Exception: java.lang.NoClassDefFoundError: com/my/ClassName at…
Thermech
  • 4,371
  • 2
  • 39
  • 60
3
votes
0 answers

mocked repository object returns empty results from controller testcase?

Repository object not mocked from controller testcase return empty object here is the below code @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes =…
2
votes
0 answers

How to populate test data before @PostConstuct?

I'm working on an application that needs to run up a TCP server as one of the first things it does. This is currently initiated via a Spring config class: @PostConstruct public void initTCPServer() { // Gets the port number and other values from…
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
2
votes
2 answers

why can't I access ApplicationContext from ApplicationContextAware implemented bean

I have a Spring JUnit tester class MySimpleTester: @ RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:/spring/mySimpleConfig.xml"}) public class MySimpleTester { @Before public void setUp() throws Exception { …
2
votes
1 answer

Failed to load ApplicationContext: Spring and junit

I'm writing unit tests for a Spring application. I have put my SpringContext.xml in pe.edu.upc.demo.configuration. SpringContext.xml:
Vj floyd
  • 31
  • 2
  • 5
1
2 3 4