Integration tests ergonomics (#7836)

Fixes #7785


  - [x] Update all integration tests with >1 files to follow the `main` pattern.
- [x] `crypto/eth2_key_derivation/tests`
- [x] `crypto/eth2_keystore/tests`
- [x] `crypto/eth2_wallet/tests`
- [x] `slasher/tests`
- [x] `common/eth2_interop_keypairs/tests`
- [x] `beacon_node/lighthouse_network/tests`
- [x] Set `debug_assertions` to false on `.vscode/settings.json`.
- [x] Document how to make rust analyzer work on integration tests files. In `book/src/contributing_setup.md`

---

Tracking a `rust-analyzer.toml` with settings like the one provided in `.vscode/settings.json` would be nicer. But this is not possible yet. For now, that config should be a good enough indicator for devs using editors different to VSCode.


Co-Authored-By: Daniel Ramirez-Chiquillo <hi@danielrachi.com>

Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
Daniel
2025-11-27 00:53:57 -05:00
committed by GitHub
parent 070e395714
commit e291955400
16 changed files with 98 additions and 3 deletions

View File

@@ -71,6 +71,47 @@ $ cargo nextest run -p safe_arith
Summary [ 0.012s] 8 tests run: 8 passed, 0 skipped
```
### Integration tests
Due to the size and complexity of the test suite, Lighthouse uses a pattern that differs from how
[integration tests are usually defined](https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html).
This pattern helps manage large test suites more effectively and ensures tests only run in release
mode to avoid stack overflow issues.
#### The "main pattern"
For packages with integration tests that require more than one file, Lighthouse uses the following
structure:
- A `main.rs` file is defined at `package/tests/main.rs` that declares other test files as modules
- In `package/Cargo.toml`, integration tests are explicitly configured:
```toml
[package]
autotests = false
[[test]]
name = "package_tests"
path = "tests/main.rs"
```
#### Rust Analyzer configuration
This pattern, combined with `#![cfg(not(debug_assertions))]` directives in test files (which
prevent tests from running in debug mode), causes Rust Analyzer to not provide IDE services like
autocomplete and error checking in integration test files by default.
To enable IDE support for these test files, configure Rust Analyzer to disable debug assertions.
For VSCode users, this is already configured in the repository's `.vscode/settings.json` file:
```json
{
"rust-analyzer.cargo.cfgs": [
"!debug_assertions"
]
}
```
### test_logger
The test_logger, located in `/common/logging/` can be used to create a `Logger` that by