Pin TestH5Z's JUnit method order to fix stale golden-order files

JUnit4's default method sorter (MethodSorters.DEFAULT) orders test
methods by a hash of the method name, not declaration order -- so any
rename or addition shifts the whole run order unpredictably relative
to a hand-maintained golden file. Both java/test/TestH5Z.java (added
this session, 13 methods) and java/src-jni/test/TestH5Z.java (5
methods, unmodified but apparently never correctly regenerated after
the testH5Zget_filter_info2 -> testH5Zget_filter_class_info rename)
had golden JUnit-TestH5Z.txt files that didn't match the real
hash-sorted order, both confirmed by computing Java's documented
String.hashCode() algorithm directly and matching it byte-for-byte
against actual CI failure output.

Verified against upstream develop (an unrelated, currently-open
develop-based PR): this test passes cleanly there, confirming the
mismatch was never a general JUnit/reflection flakiness -- it was
always a genuinely wrong reference file.

Fixed by adding @FixMethodOrder(MethodSorters.NAME_ASCENDING) to both
classes (alphabetical by method name, a properly documented and stable
JUnit4 ordering mode) and regenerating both reference files to match
the resulting deterministic order. This also makes the test immune to
the same class of breakage going forward: alphabetical order is
computable by inspection, unlike the hash order.
This commit is contained in:
Scot Breitenfeld
2026-07-16 23:42:06 -05:00
parent 7e63db2f85
commit 4e445a1997
4 changed files with 14 additions and 8 deletions
+3
View File
@@ -21,10 +21,13 @@ import hdf.hdf5lib.exceptions.HDF5LibraryException;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestH5Z {
@Rule
public TestName testname = new TestName();
@@ -2,8 +2,8 @@ JUnit version 4.13.2
.testH5Zfilter_avail
.testH5Zget_filter_class_info
.testH5Zget_filter_class_info_invalid
.testH5Zunregister_predefined
.testH5Zget_filter_info
.testH5Zunregister_predefined
Time: XXXX
+3
View File
@@ -24,10 +24,13 @@ import hdf.hdf5lib.exceptions.HDF5LibraryException;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestH5Z {
@Rule
public TestName testname = new TestName();
+7 -7
View File
@@ -1,17 +1,17 @@
JUnit version 4.13.2
.testH5Zfilter_avail
.testH5Zconfig_get_param_double
.testH5Pappend_filter_cdvalues
.testH5Pappend_filter_string
.testH5Pget_filter_params_by_idx
.testH5Zconfig_get_param_missing_key
.testH5Zconfig_get_param_bool
.testH5Zconfig_get_param_double
.testH5Zconfig_get_param_int
.testH5Zconfig_get_param_missing_key
.testH5Zconfig_get_param_str
.testH5Zfilter_avail
.testH5Zget_filter_class_info
.testH5Zget_filter_class_info_invalid
.testH5Zconfig_get_param_bool
.testH5Zunregister_predefined
.testH5Pappend_filter_string
.testH5Pappend_filter_cdvalues
.testH5Zget_filter_info
.testH5Zunregister_predefined
Time: XXXX