-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Characterization Tests for Convert #761
Open
gmjgeek
wants to merge
19
commits into
sillsdev:main
Choose a base branch
from
gmjgeek:testing/convert-characterization
base: main
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
Conversation
This file contains 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
To generate a code coverage report, use `npm run coverage`
Tests will now generated the expected output by taking a snapshot of their first run.
The command re-generates epxected output for characterization tests
gmjgeek
force-pushed
the
testing/convert-characterization
branch
from
January 9, 2025 18:00
e6f4ffd
to
4e9e67d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Support characterization tests for the convert process.
When characterization tests first run, they convert one or more test apps and save the result as a "snapshot." On subsequent runs, they compare their output with the saved snapshot, throwing an error if the two do not match.
Characterization tests are useful when refactoring, since the goal of refactoring is to keep the program's output unchanged.
Features
"Code without tests is broken by design." - Jacob Kaplan-Moss
convert
Commands
Run each command using
npm run <command>
test
test:snapshot
convert
output, and subsequent runs test against this snapshot.test:new-snapshot
Note: Snapshots are not source controlled.
To view the code coverage for the tests, append
-- --coverage
to any of the commands above, like so:Example Usage
Suppose you are refactoring
convertBooks.ts
. You may consider the following workflow:npm run test:new-snapshot -- --coverage
coverage/index.html
in your browser. Selectconvert
>convertBooks.ts
convertBooks.ts
are untested,convert/test/characterization/test_app1/input
that will cause the code to runtest_app2/input
) that will cause the code to run. Add a test case tocharacterization.test.ts
that converts this app, following the example from test_app1.What About Unit Tests?
Unit tests are better than characterization tests in several ways. Because they test isolated units of code, they are usually faster and less fragile than characterization tests. They also play a key role in Test-Driven Development (TDD), a coding style that that improves code quality through short development cycles and fast feedback.
However, unit tests are hard to write for existing code. For
convert
, adding unit tests would require significant refactoring. In the meantime, characterization tests offer quality control to facilitate refactoring.Viewing Test Coverage
When enabled, v8 reports test coverage through the terminal and through HTML. The following screenshot shows part of the terminal output from
npm run test -- --coverage
.To view the HTML report, open the local file
coverage/index.html
in a browser. In Visual Studio Code, select the file in the explorer tab and use the "Copy Path" command (Shift + Alt + C) to copy the absolute path. Paste this path into a browser, as shown below.