springjunit4classrunner

mocked repository object returns empty results from controller testcase?

寵の児 提交于 2019-12-24 12:34:05
问题 Repository object not mocked from controller testcase return empty object here is the below code @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Main.class) @WebAppConfiguration @ActiveProfiles(ApplicationConstants.DEVELOPMENT_PROFILE) public class EmployeeControllerRealTest { @Autowired private WebApplicationContext webAppContext; private MockMvc mockMvc; @Mock EmployeeRepository employeeRepository; @InjectMocks EmployeeCompositeService

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

落爺英雄遲暮 提交于 2019-12-12 16:22:58
问题 I hava this code , @RunWith(SpringJUnit4ClassRunner.class) public class JunitDemo { @Test public void testAssertArrayEquals() { byte[] expected = "trial".getBytes(); byte[] actual = "trial".getBytes(); Assert.assertArrayEquals("fail", expected, actual); } } and run the test, there are errors Caused by: java.lang.IllegalArgumentException: Can not load an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration. at org.springframework.util

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

雨燕双飞 提交于 2019-12-12 07:48:20
问题 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 org.springframework.test.context.junit4.SpringJUnit4ClassRunner.withAfterClasses(SpringJUnit4ClassRunner.java:188) at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:145) at org.junit.runners.ParentRunner.run(ParentRunner.java:235) at org.springframework.test

Cannot run powermockrule with SpringJUnit4ClassRunner in spring boot project

柔情痞子 提交于 2019-12-01 04:51:38
问题 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= MyApplication.class) @PrepareForTest(StaticClass.class) public class StaticClassTest { @Rule public PowerMockRule rule = new PowerMockRule(); @Autowired HelloCmd hello; @Test public void testGetOne() { mockStatic(StaticClass.class); when(StaticClass.getNumber())

Disable @EnableScheduling on Spring Tests

巧了我就是萌 提交于 2019-11-27 07:45:23
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 question/answer which suggests setting up profiles? Not sure how I would go about that? or if its an overkill? I was thinking of having a separate AppConfiguration for my unit tests but it feels like im repeating code twice when I do that? @Configuration @EnableJpaRepositories(AppConfiguration.DAO_PACKAGE) @EnableTransactionManagement @EnableScheduling

Disable @EnableScheduling on Spring Tests

醉酒当歌 提交于 2019-11-26 13:28:41
问题 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 question/answer which suggests setting up profiles? Not sure how I would go about that? or if its an overkill? I was thinking of having a separate AppConfiguration for my unit tests but it feels like im repeating code twice when I do that?