0

I have a standard Rust/Cargo-based codebase including the usual src folder containing production code and the usual tests folder containing integration tests. The integration tests are so complex that I would like to unit test parts of my integration test logic, to be sure that my integration tests work correctly. As an example, here is a file from my integration test suite that I would like to write unit tests for:

tests/e2e/output.rs

// complicated integration test code here

#[cfg(test)]
mod tests {

    #[test]
    fn parses_output_correctly() {
        // a unit test to verify that the complicated 
        // integration test logic above works correctly
        assert!(false)
    }
}

When I run cargo test it only executes unit tests for the production code in the src folder, but it doesn't execute this unit test because it is in the tests folder. Is there a Cargo command that executes all unit tests in the codebase, independent of whether they are in the src or tests folder? Alternatively, is there a way to run all unit tests in the tests folder?

Kevin Goslar
  • 357
  • 3
  • 8
  • This works for me. Are there any other details about what you're doing that might be relevant? – Peter Hall Apr 08 '23 at 13:27
  • Oh, it's because you have nested the file in a subdirectory of `tests/`. You need to add `tests/e2e` as a test directory. – Peter Hall Apr 08 '23 at 13:29
  • 2
    If the integration tests use such complex set-up, I would put that into a new crate, which the integration tests can use. Then you can put normal tests in the crate. – Peter Hall Apr 08 '23 at 13:33
  • That's an excellent suggestion. I will extract the complex test logic into its own crate and test that crate normally. Thank you! – Kevin Goslar Apr 09 '23 at 14:36

0 Answers0