Created
January 7, 2015 14:49
-
-
Save freekman/bbe19ee104ed07b5fa8f to your computer and use it in GitHub Desktop.
Sample Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class MyTest { | |
| public void testAddTwoNumbers() { | |
| System.out.println("Adding two numbers"); | |
| } | |
| public Date testJanuary(int year, int day) { | |
| System.out.println("Creating new date for january...."); | |
| return new Date(); | |
| } | |
| } | |
| public static interface TestObject { | |
| void another(); | |
| } | |
| public static void main(String[] args) throws InstantiationException, IllegalAccessException { | |
| runTests(MyTest.class); | |
| } | |
| private static void runTests(Class<?> clazz) throws IllegalAccessException, InstantiationException { | |
| Method[] methods = clazz.getDeclaredMethods(); | |
| Object o = clazz.newInstance(); | |
| Object[] emptyArgs = {}; | |
| for (Method each : methods) { | |
| String methodName = each.getName(); | |
| if (methodName.startsWith("test")) { | |
| // move to the next method in case when | |
| // method parameters are more then zero | |
| if (each.getParameterTypes().length != 0) { | |
| continue; | |
| } | |
| try { | |
| each.invoke(o, emptyArgs); | |
| } catch (InvocationTargetException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment