-
-
Notifications
You must be signed in to change notification settings - Fork 101
pr05 Visual Regression Testing #1: Initial Visual Testing Framework #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vaivaswat2244
wants to merge
32
commits into
processing:visual-testing
Choose a base branch
from
Vaivaswat2244:pr05-visualtests
base: visual-testing
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
2e9db0e
Update README.md
Stefterv 9e241c7
added the image comparator which is the pixel matching algorithm
Vaivaswat2244 a5ded6a
added build.gradle file
Vaivaswat2244 8e7f7d0
added the test runner
Vaivaswat2244 2f18f21
added the simple test
Vaivaswat2244 c51a8e4
Revise README for Jetpack Compose migration strategy
Stefterv 4e7183f
fixing the build issues
Vaivaswat2244 5934138
added junit as dependency
Vaivaswat2244 c4915dd
removing custom class implementation
Vaivaswat2244 d549a18
inclding visual-tests in settings
Vaivaswat2244 cac895a
fixed the overlapping cmd
Vaivaswat2244 803516f
cleaning
Vaivaswat2244 ace6f7b
adding packages
Vaivaswat2244 5e7f798
added updated screenshot structure
Vaivaswat2244 25a80ce
refactoring
Vaivaswat2244 4fcd95b
added tests in suits
Vaivaswat2244 f778c99
removed simple test
Vaivaswat2244 6224f8c
deleting earlier files
Vaivaswat2244 bf21131
updated the core/gradle file
Vaivaswat2244 86f8847
added the infrastructure
Vaivaswat2244 5a0b5e7
added some tests ported by p5js
Vaivaswat2244 fa72d2d
removing test rendering suite and its test file
Vaivaswat2244 d435e62
added screenshots
Vaivaswat2244 0d91001
config files
Vaivaswat2244 66071ac
fixed the pixeldensity to 1
Vaivaswat2244 fd72f79
Revert "fixed the pixeldensity to 1"
Vaivaswat2244 a342a77
fixed pixeldensity to 1
Vaivaswat2244 c080196
Merge branch 'visual-testing' into pr05-visualtests
Vaivaswat2244 4c190b3
Configure dependencyUpdates task in build.gradle.kts
Vaivaswat2244 60af862
removing rendering gradient screenshot
Vaivaswat2244 64c213f
Merge pull request #1012 from processing/textarea-research
SableRaf e03c099
Merge branch 'processing:main' into pr05-visualtests
Vaivaswat2244 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| plugins { | ||
Vaivaswat2244 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| java | ||
| application | ||
Vaivaswat2244 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| maven { url = uri("https://jogamp.org/deployment/maven") } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":core")) | ||
|
|
||
| // JUnit BOM to manage versions | ||
| testImplementation(platform("org.junit:junit-bom:5.9.3")) | ||
Vaivaswat2244 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| testImplementation("org.junit.jupiter:junit-jupiter") | ||
| testImplementation("org.junit.platform:junit-platform-suite:1.9.3") | ||
|
|
||
| testImplementation("org.assertj:assertj-core:3.24.2") | ||
| } | ||
|
|
||
|
|
||
| application { | ||
| mainClass.set("ProcessingVisualTestExamples") | ||
| } | ||
|
|
||
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
|
|
||
| tasks.test { | ||
| useJUnitPlatform() | ||
|
|
||
| testLogging { | ||
| events("passed", "skipped", "failed") | ||
| showStandardStreams = true | ||
| exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL | ||
| } | ||
|
|
||
| // Disable parallel execution to avoid Processing window conflicts | ||
| maxParallelForks = 1 | ||
|
|
||
| // Add system properties | ||
| systemProperty("java.awt.headless", "false") | ||
| } | ||
|
|
||
| // Task to update baselines using JUnit | ||
| tasks.register<Test>("updateBaselines") { | ||
| description = "Update visual test baselines" | ||
| group = "verification" | ||
|
|
||
| useJUnitPlatform { | ||
| includeTags("baseline") | ||
| } | ||
|
|
||
| systemProperty("update.baselines", "true") | ||
| maxParallelForks = 1 | ||
|
|
||
| testLogging { | ||
| events("passed", "skipped", "failed") | ||
| showStandardStreams = true | ||
| } | ||
| } | ||
|
|
||
| tasks.register<Test>("testShapes") { | ||
| description = "Run shape-related visual tests" | ||
| group = "verification" | ||
|
|
||
| useJUnitPlatform { | ||
| includeTags("shapes") | ||
| } | ||
|
|
||
| maxParallelForks = 1 | ||
| } | ||
|
|
||
| tasks.register<Test>("testBasicShapes") { | ||
| description = "Run basic shapes visual tests" | ||
| group = "verification" | ||
|
|
||
| useJUnitPlatform { | ||
| includeTags("basic") | ||
| } | ||
|
|
||
| outputs.upToDateWhen { false } | ||
| maxParallelForks = 1 | ||
|
|
||
| // Add test logging to see what's happening | ||
| testLogging { | ||
| events("passed", "skipped", "failed", "started") | ||
| showStandardStreams = true | ||
| exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL | ||
| } | ||
| } | ||
|
|
||
| // Task to run ONLY visual tests (no other test types) | ||
| tasks.register<Test>("visualTests") { | ||
| description = "Run all visual tests" | ||
| group = "verification" | ||
|
|
||
| useJUnitPlatform { | ||
| // Include all tests in the visual test package | ||
| includeEngines("junit-jupiter") | ||
| } | ||
|
|
||
| filter { | ||
| includeTestsMatching("visual.*") | ||
| } | ||
|
|
||
| outputs.upToDateWhen { false } | ||
| maxParallelForks = 1 | ||
|
|
||
| testLogging { | ||
| events("passed", "skipped", "failed", "started") | ||
| showStandardStreams = true | ||
| displayGranularity = 2 | ||
| } | ||
| } | ||
|
|
||
| tasks.register<Test>("testRendering") { | ||
| description = "Run rendering visual tests" | ||
| group = "verification" | ||
|
|
||
| useJUnitPlatform { | ||
| includeTags("rendering") | ||
| } | ||
|
|
||
| outputs.upToDateWhen { false } | ||
| maxParallelForks = 1 | ||
|
|
||
| testLogging { | ||
| events("passed", "skipped", "failed", "started") | ||
| showStandardStreams = true | ||
| } | ||
| } | ||
|
|
||
| tasks.register<Test>("runSuite") { | ||
| description = "Run specific test suite (use -PsuiteClass=SuiteName)" | ||
| group = "verification" | ||
|
|
||
| useJUnitPlatform { | ||
| val suiteClass = project.findProperty("suiteClass") as String? | ||
| ?: "visual.suites.AllVisualTests" | ||
| includeTags(suiteClass) | ||
| } | ||
|
|
||
| outputs.upToDateWhen { false } | ||
| maxParallelForks = 1 | ||
| } | ||
|
|
||
| // Update baselines for specific suite | ||
| tasks.register<Test>("updateBaselinesForSuite") { | ||
| description = "Update baselines for specific suite (use -Psuite=tag)" | ||
| group = "verification" | ||
|
|
||
| useJUnitPlatform { | ||
| val suite = project.findProperty("suite") as String? ?: "baseline" | ||
| includeTags(suite, "baseline") | ||
| } | ||
|
|
||
| systemProperty("update.baselines", "true") | ||
| outputs.upToDateWhen { false } | ||
| maxParallelForks = 1 | ||
| } | ||
|
|
||
| // CI-specific test task | ||
| tasks.register<Test>("ciTest") { | ||
| description = "Run visual tests in CI mode" | ||
| group = "verification" | ||
|
|
||
| useJUnitPlatform() | ||
|
|
||
| outputs.upToDateWhen { false } | ||
|
|
||
| maxParallelForks = 1 | ||
|
|
||
| testLogging { | ||
| events("passed", "skipped", "failed") | ||
| showStandardStreams = true | ||
| //exceptionFormat = org.gradle.api.tasks.testing.TestExceptionFormat.FULL | ||
| } | ||
|
|
||
| // Generate XML reports for CI | ||
| reports { | ||
| junitXml.required.set(true) | ||
| html.required.set(true) | ||
| } | ||
|
|
||
| // Fail fast in CI | ||
| failFast = true | ||
| } | ||
|
|
||
| // Clean task for visual test artifacts | ||
| tasks.register<Delete>("cleanVisualTestFiles") { | ||
| description = "Clean visual test artifacts" | ||
| group = "build" | ||
|
|
||
| delete(fileTree(".") { | ||
| include("diff_*.png") | ||
| }) | ||
|
|
||
| // Don't delete baselines by default - be explicit | ||
| doLast { | ||
| println("✓ Cleaned diff images") | ||
| println(" Baselines preserved in __screenshots__/") | ||
| println(" To clean baselines: rm -rf __screenshots__/") | ||
| } | ||
| } | ||
|
|
||
| // Separate task to clean everything including baselines (dangerous!) | ||
| tasks.register<Delete>("cleanAllVisualTestFiles") { | ||
| description = "Clean ALL visual test files INCLUDING BASELINES (use with caution!)" | ||
| group = "build" | ||
|
|
||
| delete(fileTree(".") { | ||
| include("__screenshots__/**") | ||
| include("diff_*.png") | ||
| }) | ||
|
|
||
| doFirst { | ||
| println("⚠️ WARNING: This will delete all baseline images!") | ||
| } | ||
| } | ||
|
|
||
| tasks.named("clean") { | ||
| dependsOn("cleanVisualTestFiles") | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
visual-tests/src/main/java/processing/test/visual/BaselineManager.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package processing.test.visual; | ||
Vaivaswat2244 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import processing.core.PImage; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| // Baseline manager for updating reference images | ||
| public class BaselineManager { | ||
| private VisualTestRunner tester; | ||
|
|
||
| public BaselineManager(VisualTestRunner tester) { | ||
| this.tester = tester; | ||
| } | ||
|
|
||
| public void updateBaseline(String testName, ProcessingSketch sketch) { | ||
| updateBaseline(testName, sketch, new TestConfig()); | ||
| } | ||
|
|
||
| public void updateBaseline(String testName, ProcessingSketch sketch, TestConfig config) { | ||
| System.out.println("Updating baseline for: " + testName); | ||
|
|
||
| // Capture new image | ||
| SketchRunner runner = new SketchRunner(sketch, config); | ||
| runner.run(); | ||
| PImage newImage = runner.getImage(); | ||
|
|
||
| // Save as baseline | ||
| String baselinePath = "__screenshots__/" + | ||
| testName.replaceAll("[^a-zA-Z0-9-_]", "-") + | ||
| "-" + detectPlatform() + ".png"; | ||
| newImage.save(baselinePath); | ||
|
|
||
| System.out.println("Baseline updated: " + baselinePath); | ||
| } | ||
|
|
||
| public void updateAllBaselines(ProcessingTestSuite suite) { | ||
| System.out.println("Updating all baselines..."); | ||
| List<String> testNames = suite.getTestNames(); | ||
|
|
||
| for (String testName : testNames) { | ||
| // Re-run the test to get the sketch and config | ||
| TestResult result = suite.runTest(testName); | ||
| // Note: In a real implementation, you'd need to store the sketch reference | ||
| // This is a simplified version | ||
| } | ||
| } | ||
|
|
||
| private String detectPlatform() { | ||
| String os = System.getProperty("os.name").toLowerCase(); | ||
| if (os.contains("mac")) return "darwin"; | ||
| if (os.contains("win")) return "win32"; | ||
| return "linux"; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.