Skip to content

Instantly share code, notes, and snippets.

@2tefan
Created July 27, 2022 13:31
Show Gist options
  • Save 2tefan/9f6381c5ae010211b615a57c051459a5 to your computer and use it in GitHub Desktop.
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
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