-
Notifications
You must be signed in to change notification settings - Fork 73
4. Understanding Tests System
EpicPlayerA10 edited this page Sep 5, 2025
·
4 revisions
The deobfuscator has a very clever test system. It works as follows:
- The registered samples are transformed using corresponding transformers.
- The output gets decompiled using Vineflower (FernFlower fork).
- The decompiled code is compared against the expected output.
The testing framework uses a fluent API pattern where each test is configured with:
- Name: Human-readable test description
- Transformers: List of transformer classes to apply
- Input: Type and location of test input (Java source, compiled class, or JAR)
- Output: Single class or multiple classes expected
The test suite is organized in several key directories:
-
/testData/src/java/- Contains Java source files that serve as test inputs for basic transformer functionality. These are simple, clean Java classes that get compiled and then processed by transformers. -
/testData/compiled/custom-classes/- Contains pre-obfuscated.classfiles from various real-world obfuscators, organized by obfuscator type in subdirectories. -
/testData/compiled/custom-jars/- Contains complete obfuscated JAR files for testing full application deobfuscation. -
/testData/results/(Expected Outputs) - Contains expected decompiled output files that the test framework compares against actual transformer results.
Run command mvn test in the root directory of the project. The test framework will:
- Execute all registered tests in parallel where possible
- Apply specified transformers to each test input
- Decompile results using Vineflower
- Compare against expected outputs
- Report any differences or failures
All tests are registered in TestDeobfuscation.java using a fluent API:
test("Test name")
.transformers(ExampleTransformer::new, AnotherTransformer::new)
.inputClass(InputType.JAVA_CODE, "TestClass.class")
.register();Input Methods:
-
inputClass(InputType, path)- For single class files -
inputClassesDir(InputType, path)- For directories containing multiple classes -
inputJar(path)- For JAR files (automatically usesInputType.CUSTOM_JAR)
Input Types:
-
JAVA_CODE: Source files fromtestData/src/java/ -
CUSTOM_CLASS: Compiled classes fromtestData/compiled/custom-classes/ -
CUSTOM_JAR: JAR files fromtestData/compiled/custom-jars/
-
For simple cases: Write Java source in
testData/src/java/src/main/java/ -
For real obfuscation: Place
.classfiles in appropriate subdirectory oftestData/compiled/custom-classes/ -
For complete applications: Place
.jarfiles intestData/compiled/custom-jars/ -
Register the test in
TestDeobfuscation.javawith appropriate transformers - Run once to generate expected output, then verify it's correct
- Future runs will compare against this baseline
The testing system ensures that transformers maintain their effectiveness as the codebase evolves and helps identify regressions when modifying existing functionality.