Created
July 27, 2022 13:31
-
-
Save 2tefan/9f6381c5ae010211b615a57c051459a5 to your computer and use it in GitHub Desktop.
List all Tests of a class and also prints if the test is ignored or not. The sysout can be used to create a table or just as a overview
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 void main(String[] args) { | |
Class cls = PutYourClassHere.class; | |
ArrayList<Boolean> ignoredList = new ArrayList<>(); | |
for (Method method : | |
cls.getDeclaredMethods()) { | |
boolean isTest = false; | |
boolean isIgnored = false; | |
for (Annotation annotation : | |
method.getAnnotations()) { | |
if (annotation.annotationType().getName().equals("org.junit.Test")) { | |
isTest = true; | |
} else if (annotation.annotationType().getName().equals("org.junit.Ignore")) { | |
isIgnored = true; | |
} | |
} | |
if (isTest) { | |
System.out.println(method.getName()); | |
ignoredList.add(isIgnored); | |
} | |
} | |
System.out.println("\n\n\n\nIgnored list:"); | |
for (boolean ignored : | |
ignoredList) { | |
System.out.println(ignored ? "IGNORED" : ""); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment