Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Introduce a TS SDK testing standard and approach #1043

Closed
4 tasks
danielbate opened this issue Jun 5, 2023 · 6 comments
Closed
4 tasks

Introduce a TS SDK testing standard and approach #1043

danielbate opened this issue Jun 5, 2023 · 6 comments
Assignees

Comments

@danielbate
Copy link
Contributor

danielbate commented Jun 5, 2023

As we approach mainnet, it is important we start to implement some stricter testing standards that ensures parity with the protocol/FuelVM and gives us the greatest level of confidence in the changes we are making as uptake in the SDK increases. Additionally, we can consolidate and structure our testing to give greater clarity as to what behaviours we are currently supporting. I would like to propose some MoSCoW testing standards as well as a roadmap of changes to bring the current SDK in line with the standards.

Where we are now

  • Most functions, classes and modules have a related test file that contains a mix of unit and feature tests
  • Each package approaches testing slightly differently
  • Each test case is using different language and syntax
  • Some packages are separating unit and feature tests into separate directories
  • Heavy reliance on fuel-gauge for feature and integration level testing
  • Some integration testing is done within the documentation directories
  • Ad-hoc creation of forc projects for tests

Proposed standards

  • Functions, classes and modules must have a supporting unit test file
  • Unit tests must verify all behaviours and correctness of functions, classes and modules
  • Unit tests must mock any applicable functions, classes or modules that are not the service under test
  • Unit tests must have 100% coverage of the service under test
  • Packages should have a test directory
  • Package test directories should contain fixtures and test data to be shared across tests within the package
  • Package test directories could contain mocks and stubs of functions, classes and modules
  • Package test directories should contain appropriate feature tests
  • Feature tests must simulate real word interactions to validate the behaviour of a packages features from the perspective of an SDK consumer
  • Integration tests should be used to demonstrate the interoperability of packages to deliver key behaviours to the SDK consumer
  • Test Driven Development (TDD) could be used to identify, isolate and resolve erroneous behaviours and to implement bug fixes
  • Shared test helpers and utilities should live within the utils packages
  • Test cases should follow the gherkin syntax (e.g. Given X, When Y, Then Z - for unit tests only when and then are usually required as the given is our service under test. We can then utilise the it() syntax for unit tests and test() syntax for feature and integration tests)
  • CI pipeline should enforce a coverage prerequisite to push to master (coverage level TBD)

Tasks (TBD)

  • Document the test standards and approach within the SDK
  • Refactor each package to contain a feature test directory
  • Create tests for browser compatibility - Create test to browser compatibility #284
  • Add test coverage check to CI pipeline

This should bring greater clarity to the behaviours supported by the SDK, give greater confidence in the quality of our tests and increase overall coverage as discussed in #753 . All standards and tasks are up for discussion and I would appreciate any insights 😃

@danielbate danielbate self-assigned this Jun 5, 2023
@arboleya
Copy link
Member

arboleya commented Jun 5, 2023

Good stuff @danielbate! 🚀

Somewhat related, we also have this:

We can resume the work on it now that #984 was merged.

Here's the spec from the last attempt:

@danielbate
Copy link
Contributor Author

Good point @arboleya! Will add a task for just that.

@arboleya
Copy link
Member

arboleya commented Jun 5, 2023

Do you mean other than the #284?

@danielbate
Copy link
Contributor Author

Apologies, I will not be writing any more issues but I will be using the above task list as a reference to track changes made to bring us closer to adhering to the above standards. So I just meant that I will add another task to the above list, that references #284.

@danielbate
Copy link
Contributor Author

The above requires updating due to further developments, however this is a good classification from @arboleya that will insight the specification:

Unit = Worries about units, usually mocking external stuff
Feature = Worries about features, not mocking or mocking minimally
Integration = Tests that target fuel-core locally
E2E - Tests that target fuel-core remotely

@arboleya
Copy link
Member

arboleya commented Oct 11, 2023

Here's how these tests could be spread in directories:

<package-name>
├── src
│   ├── index.test.ts # This would be a unit
│   └── index.ts
└── test
    ├── e2e
    ├── feature
    ├── fixtures
    ├── integration
    └── utils

I ended up with test/{fixtures,utils,feature} in:

It worked great, and I think all packages should segregate their tests.

This goes back to maybe re-distributing all tests from inside fuel-gauge to other packages, and although something like this might not work (because these tests must import from fuels):

  • packages/contract/test/integration/contract.test.ts

One thing that could work is:

  • packages/fuels/test/integration/contract.test.ts

@FuelLabs FuelLabs locked and limited conversation to collaborators Dec 8, 2023
@danielbate danielbate converted this issue into discussion #1491 Dec 8, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants