This is an automated email from the ASF dual-hosted git repository.

stoty pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-3 by this push:
     new 8556bade6a5 HBASE-29601 Handle Junit 5 tests in TestCheckTestClasses 
(#7311)
8556bade6a5 is described below

commit 8556bade6a516e290d8524552fce63480c56f0a2
Author: Istvan Toth <[email protected]>
AuthorDate: Thu Sep 18 08:55:15 2025 +0200

    HBASE-29601 Handle Junit 5 tests in TestCheckTestClasses (#7311)
    
    Signed-off-by: Duo Zhang <[email protected]>
    (cherry picked from commit 620f7a3a812cca4c35ced04885611a012153ee67)
---
 .../java/org/apache/hadoop/hbase/ClassTestFinder.java | 19 +++++++++++++++++--
 .../org/apache/hadoop/hbase/TestCheckTestClasses.java |  8 ++++++--
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git 
a/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java 
b/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
index 1bc648aeb0b..dc51187e3cf 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/ClassTestFinder.java
@@ -19,9 +19,11 @@ package org.apache.hadoop.hbase;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.regex.Pattern;
-import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
 import org.junit.runners.Suite;
 
 /**
@@ -46,6 +48,16 @@ public class ClassTestFinder extends ClassFinder {
     return new Class<?>[0];
   }
 
+  public static String[] getTagAnnotations(Class<?> c) {
+    // TODO handle optional Tags annotation
+    Tag[] tags = c.getAnnotationsByType(Tag.class);
+    List<String> values = new ArrayList<>();
+    for (Tag tag : tags) {
+      values.add(tag.value());
+    }
+    return values.toArray(new String[values.size()]);
+  }
+
   /** Filters both test classes and anything in the hadoop-compat modules */
   public static class TestFileNameFilter implements FileNameFilter, 
ResourcePathFilter {
     private static final Pattern hadoopCompactRe = 
Pattern.compile("hbase-hadoop\\d?-compat");
@@ -92,7 +104,10 @@ public class ClassTestFinder extends ClassFinder {
       }
 
       for (Method met : c.getMethods()) {
-        if (met.getAnnotation(Test.class) != null) {
+        if (
+          met.getAnnotation(org.junit.Test.class) != null
+            || met.getAnnotation(org.junit.jupiter.api.Test.class) != null
+        ) {
           return true;
         }
       }
diff --git 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java
index 3d3ca12bd82..c2b007280b4 100644
--- 
a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java
+++ 
b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java
@@ -45,11 +45,15 @@ public class TestCheckTestClasses {
     List<Class<?>> badClasses = new java.util.ArrayList<>();
     ClassTestFinder classFinder = new ClassTestFinder();
     for (Class<?> c : classFinder.findClasses(false)) {
-      if (ClassTestFinder.getCategoryAnnotations(c).length == 0) {
+      if (
+        ClassTestFinder.getCategoryAnnotations(c).length == 0
+          && ClassTestFinder.getTagAnnotations(c).length == 0
+      ) {
         badClasses.add(c);
       }
     }
-    assertTrue("There are " + badClasses.size() + " test classes without 
category: " + badClasses,
+    assertTrue(
+      "There are " + badClasses.size() + " test classes without category and 
tag: " + badClasses,
       badClasses.isEmpty());
   }
 }

Reply via email to