How to run all tests in a particular package with Maven?

You could use a pattern as well, for example mvn ‘-Dtest=de.mypackage.*Test’ test runs all tests in classes from package de.mypackage ending on *Test. [update 2017/12/18]: Since this became the accepted answer, here’s some further information: Maven uses the Maven Surefire plugin to execute tests. The syntax used above (qualified package name) requires Surefire version 2.19.1 … Read more

How to set JVM parameters for Junit Unit Tests?

In Maven you can configure the surefire plugin <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.9</version> <configuration> <argLine>-Xmx256M</argLine> </configuration> </plugin> If you use Maven for builds then this configuration will be carried in the source tree and applied when tests are carried out. See the Maven Surefire Plugin documentation.

How to mock method e in Log

This worked out for me. I’m only using JUnit and I was able to mock up the Log class without any third party lib very easy. Just create a file Log.java inside app/src/test/java/android/util with contents: package android.util; public class Log { public static int d(String tag, String msg) { System.out.println(“DEBUG: ” + tag + “: … Read more

Java JUnit: The method X is ambiguous for type Y

The method assertEquals(Object, Object) is ambiguous for the type … What this error means is that you’re passing a double and and Double into a method that has two different signatures: assertEquals(Object, Object) and assertEquals(double, double) both of which could be called, thanks to autoboxing. To avoid the ambiguity, make sure that you either call … Read more

Run single test from a JUnit class using command-line

You can make a custom, barebones JUnit runner fairly easily. Here’s one that will run a single test method in the form com.package.TestClass#methodName: import org.junit.runner.JUnitCore; import org.junit.runner.Request; import org.junit.runner.Result; public class SingleJUnitTestRunner { public static void main(String… args) throws ClassNotFoundException { String[] classAndMethod = args[0].split(“#”); Request request = Request.method(Class.forName(classAndMethod[0]), classAndMethod[1]); Result result = new JUnitCore().run(request); … Read more