Questions tagged [spring-junit]
67 questions
0
votes
1 answer
JUnit Mock outside rest call via restTemplate
I am trying to write an Integration test where I have an issue in mocking the rest call which is calling outside server using JUnit.
I have added a @Mock and @InjectMock on service
Service looks like this.
@Service
public class BoundaryDeltaService…

SamD
- 185
- 5
- 22
0
votes
0 answers
How to retrieve properties defined in yml in a method annotated with @BeforeClass annotation?
Hi I am having a spring boot project and I have an integration test. In my integration test i need to start an embedded elastic search instance. I have an application.yml file (src/test/resources/config/application.yml) where i define the elastic…

knowledgeseeker
- 339
- 4
- 14
0
votes
0 answers
Unable to create keyspace in EmbeddedCassandra for JUnit
Iam writing JUnits for with cassandra as DB.
Iam using EmbeddedCassandra for JUnit testing with cassandra-unit-spring library version 3.1.1.0.
However, when I start the EmbeddedCassandra server. It's not able to load CQL indicating keyspace doesn't…

Dhruv Saksena
- 209
- 2
- 13
0
votes
1 answer
Unable to run Junit case case .Throws error "Actually there were zero interactions with this mock"
I am trying to unit test a class. The class is as follows
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=MyConfig.class)
Class MyTest{
@Mock
pirvate JmsTemplate jmsTemplate;
@InjectMocks
private final ProductService…

coder
- 231
- 3
- 11
0
votes
1 answer
Getting NPE while unit testing a class using JUnit, Spring 4 and Vaadin
I am trying to unit test a very basic class that is extending some classes from Vaadin framework. But I am getting NullPointerException when I run the test.
Do I need to mock the UI class? Please guide.
Error Log:
into the enter…

Nital
- 5,784
- 26
- 103
- 195
0
votes
1 answer
Trying ot understand use of @RunWith(SpringJUnit4ClassRunner.class) and @ContextConfiguration(locations= {/dao-context.xml})
I am new to Spring and Junit testing. I am trying to understand use of @RunWith(SpringJUnit4ClassRunner.class) and @ContextConfiguration(locations= {/dao-context.xml}) on line 1 and line 2nd below in my test. dao-context has datasource ,…

Neha
- 745
- 4
- 10
- 18
0
votes
1 answer
SpringBoot JPA test beans not in context
I can't figure this out.. for some reason Spring Junit is not adding my beans to the context. Please Welp !!
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.api.demo.store.FileStorage'…

JavaHead
- 635
- 1
- 6
- 21
0
votes
1 answer
Profiles with @RunWith(SpringJUnit4ClassRunner.class)
I have two configurations for my TestSuite which provide a different beans for injection. This works so long as I set my profile with an annotation.
@ActiveProfiles( profiles={"a"}) and @ActiveProfiles( profiles={"b"})
But I seem unable to set it…

Christopher Hackett
- 6,042
- 2
- 31
- 41
0
votes
2 answers
ClassFormatError ServletException Maven project error
I have a maven project which has a test class:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({
"file:../test-war/src/main/webapp/WEB-INF/applicationContext.xml",
…

kandan
- 715
- 2
- 12
- 39
0
votes
0 answers
Spring StandaloneMockMvcBuilder not able to resolve dynamic RequestMapping in Controller under test
We have Controllers with dynamic request mapping:
(@RequestMapping(method = RequestMethod.POST, value = "${api.emailverification.officialvalidate.POST.uri}")
These request mappings are resolved via properties file in spring Environment.
Now, in our…
0
votes
0 answers
Access Spring profiles in spring-junit test classes
I am using Spring 4.3.0.I am writing a SDK in that i am having the following classes,
Providers.java
@ComponentScan
@Service
//@PropertySource("classpath:application.properties")
public class Providers {
@Autowired
ApplicationContext…

VelNaga
- 3,593
- 6
- 48
- 82
0
votes
2 answers
Unit Test with Spring JPA - @Autowired is not working
I have a unit test and a helper class.
Unfortunely the Helper class' autowire does not work.
It works fine in MyTest class.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:context.xml"})
@Component
…

NoobieNoob
- 887
- 2
- 11
- 31
0
votes
2 answers
Failed to delete a file in windows environment
I am working in windows environment.
In my tearDown() method, deleteSucceeded is returning false.
File is never getting deleted although it is there in the desired location.
The strange thing is that:
In unix environment, the same code is working…

sjain
- 23,126
- 28
- 107
- 185
0
votes
0 answers
Native query not running in HsqlDb using Spring-Junit4
I have a method in my DAO which is querying a Oracle database and it is working fine in the application. However for testing we are using an Hsqldb and using Spring-junit for the tests. The same method returns an error during the tests because as…

fgonzalez
- 3,787
- 7
- 45
- 79
0
votes
1 answer
How to mock getNamedParameterJdbcTemplate()
I am trying to mock a DAO implementation class that extends NamedParameterJdbcDaoSupport
This is how my DAO interface looks like:
public interface TestDAO{
List search();
}
This is how my implementation class is:
public class…

Aniks
- 1,011
- 3
- 17
- 29