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

Table-Driven-Tests (TDT) improvement to remove context initialization #556

Open
7 tasks
lumtis opened this issue Feb 23, 2022 · 0 comments
Open
7 tasks
Labels
Epic Epic issue test Improve tests

Comments

@lumtis
Copy link
Contributor

lumtis commented Feb 23, 2022

#540 (comment)

Many unit tests we use in our codebase use Table Driven Tests (TDT)
The idea is to create a table of test cases containing input, expected output for better maintainability and visualisation.

In many of these tests, we perform first initialization before the table declaration. Most of the time, initialization of coordinators, chains, etc...
This context initialization makes our tests less in the idea of TDT where the whole purpose of a test case should be visualized in the test case itself and make the tests less visual and maintainable.

The idea would be to investigate how we could incorporate the context initialization in the test case itself as the initial state of the test case. For example, describing the list of coordinators in the test case, the coordinators are then initialized in the body of the TDT

Example:

[coordinators initialization]
[chains initialization]

foreach []testCase{
  {
    input
    expectedOutput
  }
  ....
} {
  [assertion]
}

would become

foreach []testCase{
  {
    initialState{
      coordinators
      chains
    }
    input
    expectedOutput
  }
  ....
} {
  [coordinators initialization]
  [chains initialization]
  [assertion]
}

Implementation example:

Test for claim CompleteMission:

func TestKeeper_CompleteMission(t *testing.T) {

I'm open to any feedback, suggestion, critic on this implementation

Tasks

@lumtis lumtis added test Improve tests research The task implies doing research and proposing a solution before implementation labels Feb 23, 2022
@lumtis lumtis added this to the Test Refactoring milestone May 26, 2022
@lumtis lumtis added Epic Epic issue and removed research The task implies doing research and proposing a solution before implementation labels Jun 9, 2022
@lumtis lumtis changed the title Investigate Table-Driven-Tests improvement to remove context initialization Table-Driven-Tests (TDT) improvement to remove context initialization Jun 9, 2022
@lumtis lumtis removed this from the Test Refactoring milestone Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Epic Epic issue test Improve tests
Projects
None yet
Development

No branches or pull requests

1 participant