JUnit tests always rollback the transactions

It should work, like you expect it, but may be you open another transaction within your class under test or you have an other feature/or bug somewhere. Btw this annotations should be enougth: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {“classpath:com/my/app/context.xml”} @Transactional public class PerformanceTest { @Test @Rollback(false) public void testMsisdnCreationPerformance() { // Create a JPA entity // Persist … Read more

Junit assert OR condition in my test case

You can use Hamcrest matchers to get a clearer error message here: int i = 2; assertThat(i, Matchers.either(Matchers.is(3)).or(Matchers.is(5)) or int i = 2; assertThat(i, Matchers.anyOf(Matchers.is(3),Matchers.is(5))); This will more clearly explain: Expected: (is <3> or is <5>) but: was <2> showing exactly the expectation and the incorrect value that was provided.

Spring JUnit Test Error

I had this exact same issue when upgrading from Spring 3.0.6 and to 3.1.0 release. Here is the solution: Some of your dependencies are listed as being the 3.1.0 version, but they resolve their transitive dependencies to the older versions which don’t have the method listed in the error message. If you use Eclipse, open … Read more

How to handle ordering of @Rule’s when they are dependent on each other

EDIT: With the recently released Junit 4.10, you can use RuleChain to chain rules correctly (see at the end). You could introduce another private field without the @Rule annotation, then you can reorder your code as you wish: public class FolderRuleOrderingTest { private TemporaryFolder privateFolder = new TemporaryFolder(); @Rule public MyNumberServer server = new MyNumberServer(privateFolder); … Read more

SpringBootTest : No qualifying bean of type ‘org.springframework.test.web.servlet.MockMvc’ available:

Hope you have spring-boot-starter-web dependency. Not sure which version of Spring boot you use, but build mockMvc this way instead? @RunWith(SpringRunner.class) @SpringBootTest public class ApplicationTest { @Autowired private WebApplicationContext webApplicationContext; private MockMvc mockMvc; @Before public void setUp() { mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); }

Specifying an order to junit 4 tests at the Method level (not class level)

If you’re sure you really want to do this: There may be a better way, but this is all I could come up with… JUnit4 has an annotation: @RunWith which lets you override the default Runner for your tests. In your case you would want to create a special subclass of BlockJunit4ClassRunner, and override computeTestMethods() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)