Using reflection isn't the best method, but you can do it something like this:
public static void main(String[] args) throws Exception {
Computer computer = new Computer();
JUnitCore jUnitCore = new JUnitCore();
Field field = JUnitCore.class.getDeclaredField("fNotifier");
field.setAccessible(true);
RunNotifier runNotifier = (RunNotifier) field.get(jUnitCore);
runNotifier.pleaseStop();
jUnitCore.run(computer, BeforeAfterTest.class, AssertionErrorTest.class);
}
This will throw a org.junit.runner.notification.StoppedByUserException.
If you want more flexibility or control, a better way to do the above is to just copy the bits you want from JUnitCore into your class, and then you've got direct control over the notifier, and listeners, etc. This is the nicest way to do it. JUnitCore isn't really deisgned to be extended.