sharkdp / hexyl

A command-line hex viewer
Apache License 2.0
8.93k stars 227 forks source link

Optimize Test Organization #70

Closed liangyongrui closed 4 years ago

sharkdp commented 4 years ago

Thank you for your contribution.

Could you tell us what the benefits would be?

liangyongrui commented 4 years ago

Thank you for your contribution.

Could you tell us what the benefits would be?

I found that the previous unit tests were all public apis.

I agree with the "The Rust Programming Language":

In Rust, integration tests are entirely external to your library. They use your library in the same way any other code would, which means they can only call functions that are part of your library’s public API. Their purpose is to test whether many parts of your library work together correctly. Units of code that work correctly on their own could have problems when integrated, so test coverage of the integrated code is important as well. To create integration tests, you first need a tests directory.

sharkdp commented 4 years ago

I found that the previous unit tests were all public apis.

Really? Isn't that why we have a cfg(test) feature gate?

I agree with the "The Rust Programming Language":

That is true for integration tests. But not for unit tests. https://doc.rust-lang.org/book/ch11-03-test-organization.html#unit-tests

So your tests/lib_test.rs is fine, because those are more integration-style tests. But the squeezer-tests should probably remain in that module.

What do you think?