4.5 KiB
4.5 KiB
Image generation test plan — ImageSharp-only (multiplatform)
Goal
Create an automated, cross-platform test project that validates ImageCreatorImageSharp behavior by generating synthetic input images and pixel-inspecting outputs produced by the library.
Decisions
- Test only
ImageCreatorImageSharp(multiplatform). - Test project targets
net10.0(not Windows-only) and uses SixLabors.ImageSharp for both generation and verification; avoidSystem.Drawing.Commonin tests. - Inputs are programmatically generated images (no checked-in large binaries).
- Verification uses pixel inspection (sample regions, color averages, non-background pixel counts).
Project
- Name:
MaddoShared.ImageSharpTests(folder:MaddoShared.ImageSharpTests/) - TargetFramework:
net10.0(no Windows-only flags) - Package references:
MSTest.TestFramework/MSTest.TestAdapter/Microsoft.NET.Test.SdkFluentAssertionsMoq(if needed for loggers)SixLabors.ImageSharpandSixLabors.ImageSharp.Drawing(for image creation and pixel inspection)Microsoft.Extensions.Logging.Abstractions(lightweight logging)
- ProjectReference:
../MaddoShared/MaddoShared.csproj
Helpers (tests)
TempWorkspace— creates temporarySourceandDestfolders, cleans up on dispose.TestImageFactory— creates synthetic JPEG/PNG inputs and in-memory logo PNG bytes. Also can write EXIF orientation values.PixelInspector— loads output using ImageSharp and exposes:CountNonBackgroundPixels(path, Rectangle region, Rgba32 background, int tolerance)SampleAverageColor(path, Rectangle region)- Region helpers: top/bottom/left/right/center/quadrant rectangles for given image sizes
CreatorFactory— buildsPicSettingsdefaults andImageCreatorImageSharpinstances.
Test cases (high-level)
- Image resizing: verify big and small output dimensions respect settings.
- Text positioning: for
Posizione= ALTO/CENTRO/BASSO andAllineamento= SINISTRA/CENTRO/DESTRA assert text pixels appear in expected regions. - Text content: baseline (empty) vs non-empty comparisons to ensure text changes output; EXIF-vertical photo selects
TestoFirmaV. - Logo positioning: use a solid-color logo (e.g., pure red PNG) and verify red pixels appear in the expected quadrant for combinations of
LogoPosizioneH×LogoPosizioneVand with margins (absolute and percentage). - Logo features: opacity (logo color blending) and color-key transparency.
- EXIF orientation: ensure rotation is applied and output contains no EXIF orientation tag.
Verification approach
- For text: compare non-background pixel count in the target band vs opposite band (thresholded) to avoid brittle exact glyph placement checks.
- For logo: sample the quadrant where the logo should be; count logo-colored pixels and assert above threshold.
- For opacity: sample average color in logo region and assert it is blended when opacity <100%.
Scope boundaries
- In scope:
ImageCreatorImageSharpbehavior: resize, EXIF rotation, text presence/position, logo position/opactiy, thumbnails. - Out of scope: OCR verification of exact text glyphs, font-subpixel metrics, performance testing.
Implementation notes
- Keep tests deterministic by creating solid-color inputs and simple logos.
- Use modest image sizes (e.g., 800×600) so tests run fast.
- Carefully choose thresholds for pixel-count assertions to be robust across fonts and rendering differences.
Run & validate
- Build:
dotnet build MaddoShared.ImageSharpTests - Test:
dotnet test MaddoShared.ImageSharpTests
Files to add
MaddoShared.ImageSharpTests/MaddoShared.ImageSharpTests.csprojMaddoShared.ImageSharpTests/Helpers/TempWorkspace.csMaddoShared.ImageSharpTests/Helpers/TestImageFactory.csMaddoShared.ImageSharpTests/Helpers/PixelInspector.csMaddoShared.ImageSharpTests/Helpers/CreatorFactory.csMaddoShared.ImageSharpTests/Tests/ImageResizingTests.csMaddoShared.ImageSharpTests/Tests/TextPositioningTests.csMaddoShared.ImageSharpTests/Tests/LogoPositioningTests.csMaddoShared.ImageSharpTests/Tests/ExifOrientationTests.csdocs/image-generation-tests-plan.md(this file)
Next steps
- Create the
MaddoShared.ImageSharpTestsproject and add the helper files. - Implement the first set of tests (resizing + a simple text presence test) to validate the testing harness.
- Iterate thresholds and add remaining tests.