Skip to content

In Process Integration Tests #6423

Closed
Closed
@aaronc

Description

Summary

Running integration tests in a single process will improve code coverage metrics and make debugging easier.

Problem Definition

Currently CLI integration tests work by building CLI binaries and then calling the CLI binaries as sub-processes. While this is a somewhat realistic simulation of actual usage, it has the following downsides:

  • integration test coverage isn't reflected in code coverage metrics, therefore we can't
    • account for code coverage which is actually achieved by integration tests, and
    • have no way of knowing which CLI/REST/etc. code isn't covered
  • debugging is hard - there's no way to set breakpoints for failure either in the simd or simcli binaries

Proposal

Use the new testutil package to test command instances directly and in-process. As we're refactoring existing tests, we should be careful to construct/replace clean auxiliary functions for common operations (e.g. MsgSend).


Original Proposal (for future reference)

1. Make *cobra.Cmds respect stdin, stdout, & args overrides

All CLI methods are implemented using *cobra.Cmd which has SetIn, SetOut, SetArgs, etc. methods to override the default os.StdIn, os.Stdout, os.Args. As long as Cmds and the code they call respect these (which so far seems to be generally the case), Cmds can be called in the same process as test code. Only minimal changes to CLI test code would be required, mainly the fixtures.

2. Expose rootCmd's to integration test fixture

  • Expose GetRootCmd func's for simd/simcli
  • Setup build flags for cli_test_in_process to either use binaries as we currently do -or- use simd/simcli GetRootCmds and run in process
  • Adjust cli test fixture accordingly

3. Make every cli test suite a testify Suite that can be re-used by other apps

Each CLI test file should be restructured into a Suite that takes a config object. The config object will define how tests are run and will allow other apps building on the SDK to inject their own app config's and run the same suites for their apps.

4. Run all CLI tests in the SDK from a single simapp/cli_test.go file

This single simapp/cli_test.go file should import the suites from each module, populate them with the simapp config and run them one by one. This file would serve as an example for other apps as to how to setup their CLI tests.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions