Questions tagged [spring-junit]
67 questions
                    
                    33
                    
            votes
                
                7 answers
            
        Spring jUnit Testing properties file
I have a jUnit Test that has its own properties file(application-test.properties) and its spring config file(application-core-test.xml). 
One of the method uses an object instantiated by spring config and that is a spring component. One of the…
         
    
    
        Nikhil Das Nomula
        
- 1,863
- 5
- 31
- 50
                    15
                    
            votes
                
                1 answer
            
        No bean named 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined
i am trying to run full package of junit test classes, and i have an audit classes for my domain classes as follows:
    @PrePersist
    public void prePersist(AuditableEntity e) {
      UserService userService =…
         
    
    
        Mahmoud Saleh
        
- 33,303
- 119
- 337
- 498
                    14
                    
            votes
                
                2 answers
            
        Autowiring Spring services into JUnit tests
Following is the service.
@Service
public class MyService  {
   public List getIds(Filter filter){
      // Method body
   }
}
And a configuration class.
@Configuration
public static class MyApplicationContext {
    @Bean
    public… 
         
    
    
        orwe
        
- 233
- 1
- 3
- 10
                    13
                    
            votes
                
                2 answers
            
        JUnit Rule using a spring bean
I have a test class which loads a test spring application context, now I want to create a junit rule which will setup some test data in mongo db. For this I created a rule class. 
public class MongoRule extends ExternalResource {
    private… 
         
    
    
        Sunny Agarwal
        
- 1,451
- 4
- 18
- 36
                    12
                    
            votes
                
                2 answers
            
        @ExtendWith(SpringExtension.class) not working
I'm trying to use Junit 5 on a spring-boot 2.x project to test a Controller.
The following works fine
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static…
         
    
    
        Anand Rockzz
        
- 6,072
- 5
- 64
- 71
                    9
                    
            votes
                
                2 answers
            
        Hibernate :java.lang.NoSuchMethodError:javax/validation/spi/ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider
We are executing Junit suite for Spring-Hibernate based application( using spring text conext Unit testing framework).and using ANT for building and below Hibernate Jars are there in build path…
         
    
    
        Om P
        
- 117
- 1
- 3
- 9
                    8
                    
            votes
                
                3 answers
            
        Junit HSQLDB - user lacks privilege or object not found - THIS_.oh-ordnbr
I am getting an exception when my column name contains hyphen "-"
    Entity : this is the entity name.
    @Entity
    @Table(name = "RequestHeader")
    public class RequestHeader implements Serializable { 
    ....
    ....    
    @Column(name =…
         
    
    
        Ram Subramanian
        
- 101
- 1
- 1
- 4
                    6
                    
            votes
                
                3 answers
            
        How to test a controller with constructor injection by MockMvc
I have a controller with constructor injection
@RestController
@RequestMapping("/user")
public class MainController {
    private final UserMapper userMapper; // autowired by constructor below
    public MainController(UserMapper userMapper) {
   …
         
    
    
        Daniel
        
- 85
- 1
- 1
- 6
                    6
                    
            votes
                
                1 answer
            
        Spring: Why is @PreDestroy not called at end of each test class?
I have an integration test class annotated as follows
@WebAppConfiguration
@ContextConfiguration(classes = {AppConfiguration.class})
@RunWith(SpringJUnit4ClassRunner.class)    
public class CacheConsumerTest {
}
Here's my…
         
    
    
        Popcorn
        
- 5,188
- 12
- 54
- 87
                    5
                    
            votes
                
                0 answers
            
        How to add RunListener and TestExecutionListeners when running with Cucumber
Our current testing framework is running with junit + spring + selenium.
Our tests use both junit's org.junit.runner.notification.RunListeners and spring org.springframework.test.context.TestExecutionListeners.
This is how the test definition looks…
         
    
    
        Dana Shalev
        
- 1,894
- 1
- 13
- 13
                    4
                    
            votes
                
                2 answers
            
        Spring Boot Unit Test @Value from .properties File gives NullPointerException
I am trying to read a value from a properties file for a unit test case in Spring Boot. I have two config.properties files, one in src/main/resources:
prop = some-value
and one in src/test/resources:
prop = some-test-value
Main Application…
         
    
    
        shinvu
        
- 601
- 2
- 7
- 23
                    4
                    
            votes
                
                2 answers
            
        Java Spring MVC - java.lang.NoClassDefFoundError: javax/servlet/ServletContext
I am trying to write some JUnit testing for my Java Spring application but I keep getting this error java.lang.NoClassDefFoundError: javax/servlet/ServletContext. 
Test class: 
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes =…
         
    
    
        peech
        
- 931
- 3
- 12
- 23
                    3
                    
            votes
                
                1 answer
            
        junit spring jms listener
I want to unit test a simple jms listener code below 
@Component
public class NotificationReader {
    @JmsListener(destination = "myAppQ")
    public void receiveMessage(NotificationMessage notificationMessage) {
       …
         
    
    
        lives
        
- 1,243
- 5
- 25
- 61
                    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
                
                1 answer
            
        Why I am getting java.lang.NoSuchMethodError while running spring based camel junit test case
I have to test my route builder using JUnit and I am getting java.lang.NoSuchMethodError, Am I missing any configuration or the way I am accessing my route builder should be changed. Please find RouteBuilder, context and Junit class…
         
    
    
        bala
        
- 55
- 1
- 7