Skip to content
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

Additional unit test capabilities #192

Merged
merged 16 commits into from
Dec 24, 2019
Merged

Conversation

MaximMoinat
Copy link
Collaborator

@MaximMoinat MaximMoinat commented Oct 23, 2019

This PR adds the following functions and features to the unit test framework:

  • writeSourceCsv(directory, separator) to generate CSV source data files
  • getTestsOverview() to create list with all tests. closes Testing Framework- List of test cases #124
  • summaryTestFramework() to get a summary of the test framework, including the % of mapped source/target fields that have a mapping. closes Add ability to track ETL unit test coverage #180
  • getUntestedSourceFields(), getUntestedTargetFields() return the source/target fields that are not tested yet.
  • outputTestResultsSummary(connection, schema) Function to output a summary of the test results, with
  • Several small fixes (refactoring, improved variable name cleaning)

Note: one change to the insert sql was made to allow proper csv source files output. Variables set to NULL were ignored previously when generating the insert sql. With this change a NULL value will be explicitly inserted. This should not change the behaviour of the insert.
https://github.com/OHDSI/WhiteRabbit/pull/192/files#diff-02f1595ce6665edb5f8d77d478bc3853R265-R266

@MaximMoinat
Copy link
Collaborator Author

Example output of getTestsOverview():

  testId       testDescription  testType          testTable
1      1       My Expectations    Expect             person
2      1       My Expectations    Expect observation_period
3      1       My Expectations    Expect   visit_occurrence
4      2    My No Expectations Expect No             person
5      2    My No Expectations Expect No        observation

Example output of summaryTestFramework():

                            summary
n_tests                        7.00
n_cases                        4.00
n_source_fields_tested         4.00
n_source_fields_mapped_from    8.00
source_coverage (%)           50.00
n_target_fields_tested         2.00
n_target_fields_mapped_to     45.00
target_coverage (%)            4.44

Example output of outputTestResultsSummary(connection, schema):

FAILED unit tests: 1/178 (0.6%)
  ID                     DESCRIPTION          TEST STATUS
2  1 RMG-PD1 is assigned person_id 1 Expect person   FAIL

or

All 178 tests PASSED

To be documented on the wiki.

@blootsvoets
Copy link
Collaborator

LGTM. Food for thought: why not use out.writeln() instead of r.add() to append lines in ETLTestFrameWorkGenerator?

Unrelated to this PR, but still triggered by it: WriteTextFile swallows exceptions without proper messages to the user (only stack traces). This could be improved by just using Files.newBufferedWriter and catching exceptions appropriately. If printing capabilities are required, i.e. writer.println(), then this can be wrapped by a PrintWriter.

try (BufferedWriter bw = Files.newBufferedWriter(path);
        PrintWriter writer = new PrintWriter(bw)) {
} catch (FileNotFoundException ex) {
    // ...
} catch (IOException ex) {
    // ...
}

@MaximMoinat MaximMoinat mentioned this pull request Nov 11, 2019
@MaximMoinat MaximMoinat merged commit 9d7f595 into OHDSI:develop Dec 24, 2019
@MaximMoinat MaximMoinat deleted the unit-test branch December 24, 2019 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants