Unity-Technologies / Unity-Technologies/UnityDataTools

Tests: extract the duplicated console-capture and output-folder scaffolding

Open
#139 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
821
Forks
71
Avg merge
3h 13m
Merged PRs (30d)
9

Description

The test fixtures in UnityDataTool.Tests each re-implement the same two pieces of scaffolding.

Running a command and capturing its output. Every fixture that needs to assert on what a command
printed redirects Console.Out / Console.Error into a StringWriter, calls Program.Main, and
restores the originals in a finally. There are three named variants of this —
AnalyzeOverwriteTests.RunAnalyze (stderr only), AnalyzeExitCodeTests.RunAnalyze (both streams),
FindRefsTests.RunFindRefsOn — plus a large number of copies written inline inside individual test
methods, for example the two no-TypeTree tests in UnityDataToolPlayerDataTests.

Output folder setup and teardown. OneTimeSetup creates a per-fixture folder under the test
directory and SetCurrentDirectorys into it; Teardown calls SqliteConnection.ClearAllPools() and
deletes the folder's files and subdirectories. This block is duplicated nearly verbatim across
roughly 15 fixtures.

Neither is causing bugs, but it means a change to how tests run a command or clean up has to be made
in many places, and each new fixture starts by copying 40 lines.

Suggested shape:

  • A shared helper that runs a command and returns (exitCode, stdout, stderr) — or combined output,
    which is what most assertions want. SQLTestHelper is the project's existing shared helper but is
    SQL-specific, so a small separate helper class is probably a better home.
  • A base fixture (or a helper method) for the output-folder creation and teardown.

Then migrate the fixtures over, which can be done incrementally.

Raised during the review of the fix for #115, which added one more copy of both patterns.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the UnityDataTool.Tests fixtures named in the issue, especially AnalyzeOverwriteTests, AnalyzeExitCodeTests, FindRefsTests, and UnityDataToolPlayerDataTests, and compare their command-capture and folder setup code. Review SQLTestHelper before choosing a separate shared helper or base fixture. Done means the duplicated patterns are migrated across the fixtures and the test suite still passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
testing-qa
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.