Documention tests does not work


According to the Docs something like this should panic because of assertion failed
/// Do somework /// # Example /// /// assert_eq!(9, 21); /// pub foo() { ... }

but nothing happen and in cargo test output i get thing message running 0 tests why is that ?


Are you sure the test is marked using triple backticks as shown in the docs? Rustc has to be able to distinguish code from prose.


Yes it’s but i just can’t write it here


Is this for a library crate or a binary crate? Cargo will only run doctests for library crates. (If you are developing an executable, you might want to split testable code into a separate library.)


What do you mean? It should look like this:

/// Do somework
/// # Example
/// ```
/// assert_eq!(9, 21);
/// ```
pub foo() {

This is demonstrated in the documentation tests section of your link:


it look like this i just can’t write the mark above assert_eq! here


yes it’s a library crate


What does this mean? Why can’t you? What error do you get? Can you share what you’re writing?


I might be wrong, but I my guess is that @hackereg35 complains that Discourse eats triple quote marks (```), while they are present in code.

Another possible explanation for the original issue is that the module is not properly connected to the crate. That is, there is, but no corresponding mod foo; in Are usual tests function (#[test] fn foo() {}) work in this file?