Skip to content

Instantly share code, notes, and snippets.

@heyhuyen
Last active February 7, 2017 23:37
Show Gist options
  • Save heyhuyen/49a7f85a0c279557159080aab98996fd to your computer and use it in GitHub Desktop.
Save heyhuyen/49a7f85a0c279557159080aab98996fd to your computer and use it in GitHub Desktop.
Simple Java Environment Setup for command line usage (Mac)
# See https://www.tutorialspoint.com/junit/junit_executing_tests.htm
# ~/.bash_profile
export JAVA_HOME=/Library/Java/Home
export JUNIT_HOME=/Library/JUNIT
export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit-4.10.jar:.
# TestJunit.java
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJunit {
@Test
public void testAdd() {
String str = "Junit is working fine";
assertEquals("Junit is working fine",str);
}
}
# TestRunner.java
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(TestJunit.class); // <-- name of test class here!
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment