How to make JUnit test cases execute in parallel? [duplicate]

Junit4 provides parallel feature using ParallelComputer: public class ParallelComputerTest { @Test public void test() { Class[] cls={ParallelTest1.class,ParallelTest2.class }; //Parallel among classes JUnitCore.runClasses(ParallelComputer.classes(), cls); //Parallel among methods in a class JUnitCore.runClasses(ParallelComputer.methods(), cls); //Parallel all methods in all classes JUnitCore.runClasses(new ParallelComputer(true, true), cls); } public static class ParallelTest1 { @Test public void a(){} @Test public void b(){} … Read more

How to use Hamcrest to inspect Map items

Youu could just use contains or containsInAnyOrder. True, you’ll have to list all items in the List that way, but it works cleaner than hasItem: @SuppressWarnings(“unchecked”) @Test public void mapTest() { Map<String, List<MyItem>> map = new HashMap<String, List<MyItem>>(); map.put(“one”, asList(new MyItem(“1”), new MyItem(“one”))); assertThat(map, hasEntry(is(“one”), containsInAnyOrder(hasProperty(“name”, is(“one”)), hasProperty(“name”, is(“1”))))); }

AssertJ: For a Pojo how to check each nested Property/Field in one chained sentence

I think the best way is to extract all the properties/fields and then checks it does not contain null. Example: TolkienCharacter frodo = new TolkienCharacter(“Frodo”, 33, HOBBIT); // support nested properties: assertThat(frodo).extracting(“name”, “age”, “race.name”) .doesNotContainNull() .containsExactly(“Frodo”, 33, “Hobbit”); Note that you can also use lambdas to extract values from the object under test. assertThat(frodo).extracting(TolkienCharacter::getName, character … Read more

Javadoc in JUnit test classes?

I use Javadoc in my testing a lot. But it only gets really useful when you add your own tag to your javadoc. The main objective here is to make the test understandable for other developers contributing to your project. And for that we don’t even need to generate the actual javadoc. /** * Create … Read more

@RunWith(SpringRunner.class) vs @RunWith(MockitoJUnitRunner.class)

The SpringRunner provides support for loading a Spring ApplicationContext and having beans @Autowired into your test instance. It actually does a whole lot more than that (covered in the Spring Reference Manual), but that’s the basic idea. Whereas, the MockitoJUnitRunner provides support for creating mocks and spies with Mockito. However, with JUnit 4, you can … Read more

Run parallel test task using gradle

The accepted answer above works but the Gradle documentation here suggests you use maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 I tried both and after testing both on a 2.3 GHz Intel Core i7 Mac Book Pro with 16GB RAM (4 cores with hyperthreading) test { maxParallelForks = Runtime.runtime.availableProcessors() } and test { maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: … Read more

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