junit4

Spring boot integration test fails with Neo4j

安稳与你 提交于 2019-12-23 02:19:21
问题 I am new to spring boot. I use Spring Boot 1.5.1 GA and Neo4j starter of spring boot. I tried to create my very first integration test to whether I can insert a new object into the graph database. Here is my test class: package hu.bookandwalk; import static org.junit.Assert.assertEquals; import java.time.LocalDateTime; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.neo4j.ogm.testutil.TestServer; import org

transactions not working with Spring 3.1 – H2 – junit 4– hibernate 3.2

こ雲淡風輕ζ 提交于 2019-12-22 10:45:04
问题 I have the following test.. @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"/schedule-agents-config-context.xml"}) @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true) @Transactional public class H2TransactionNotWorkingTest extends SubmitAgentIntegratedTestBase { private static final int FIVE_SUBMISSIONS = 5; @Autowired private ApplicationSubmissionInfoDao submissionDao; private FakeApplicationSubmissionInfoRepository

Mock File, FileReader and BufferedReader class using Mockito

最后都变了- 提交于 2019-12-22 05:17:45
问题 I got below code in a method which I want to test File f = map.get("key1") BuffereReader r = new BufferedReader(new FileReader(f)); String line=null; do { line=r.readLine(); } while(r!=null); I want to mock this operation so that I can pass the content of the file from the JUnit test case. I have done below: Map fles = Mockito.mock(ConcurrentHashMap.class); File file = Mockito.mock(File.class); Mockito.when(files.get("key1")).thenReturn(file); FileReader fileReader = Mockito.mock(FileReader

Testing multiple interface implementations with same tests - JUnit4

对着背影说爱祢 提交于 2019-12-22 03:59:05
问题 I want to run the same JUnit tests for different interface implementations. I found a nice solution with the @Parameter option: public class InterfaceTest{ MyInterface interface; public InterfaceTest(MyInterface interface) { this.interface = interface; } @Parameters public static Collection<Object[]> getParameters() { return Arrays.asList(new Object[][] { { new GoodInterfaceImpl() }, { new AnotherInterfaceImpl() } }); } } This test would be run twice, first with the GoodInterfaceImpl then

Run JUnit4-Tests parallel in Eclipse

杀马特。学长 韩版系。学妹 提交于 2019-12-22 03:50:33
问题 maven-surefire-plugin enables running JUnit tests in parallel[1] - is there way to run JUnit-Tests in Eclipse in parallel, too? [1] e.g. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> <configuration> <parallel>methods</parallel> </configuration> </plugin> "Running tests in parallel" https://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html 回答1: You can use tempus-fugit to run tests in parallel in

Cannot JUnit test using Spring

三世轮回 提交于 2019-12-22 01:44:55
问题 My test is defined as follows: package com.mytest; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class SpringTestCase { @Test public void testSave_success() { fail("Not implemented"); } } My intention is to just run this test and fail! My test's spring configuration file is located in: /com/mytest/SpringTestCase-context.xml The contents of my spring configuration file are as follows: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org

How to force a fresh version of the Spring context BEFORE the test executes

拥有回忆 提交于 2019-12-22 01:27:29
问题 I use the SpringJUnit4ClassRunner for writing integration tests. I also use @DirtiesContext for tests that leave the context in an broken state behind and that works just fine. But now I have a test the sets an important SystemProperty in an static initializer, which in turn is used in the Spring context. This again works fine when the test executes on its own. But when I run the test with other tests the Spring context gets already created with out that property set and gets reused by my new

How can I initialize a Spring applicationContext just once for all tests

自古美人都是妖i 提交于 2019-12-21 22:47:33
问题 I have a set of tests based which need a spring context. For fast test execution I want to make sure that the Spring context is initialized just once, then all the tests should be run against this context, then it should shut down. I already tried the following approaches: Use @RunWith(SpringJUnit4ClassRunner.class) and @ContextConfiguration(MyAnnotatedConfig.class) to initialize the spring context Use a @RunWith(SpringJUnit4ClassRunner.class) and @TestExecutionListeners(

Character encoding in IDEA output of AssertionError

泪湿孤枕 提交于 2019-12-21 17:25:58
问题 I am using IntelliJ IDEA 12.0.4. Have some tests. When i'm running one using JUnit4 framework my Assertion Error looks like: java.lang.AssertionError: Status should be: Черновик expected [true] but found [false] If i am using a TestNG it look like this: java.lang.AssertionError: Status should be: Черновик expected [true] but found [false] All other cyrillic outputs work fine on both framework, only assertion text won't. Project files encoding set to UTF-8. Update: For example simple

NoClassDefFoundError for MockitoInvocationHandler class

梦想的初衷 提交于 2019-12-21 12:18:50
问题 I am using mockito-all-1.9.5-rc1.jar and powermock-mockito-1.4.12-full.jar . When I run this simple unit test for mocking final method in non-final class. import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) @PrepareForTest(ABC.class) public class