× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How do I test private methods in Rust?

Chris Morgan
Jul 08, 2015
<p>When using <code>#[test]</code>, there’s nothing special about private or public methods—you’re just writing perfectly normal functions that can access anything they can access.</p> <pre><code>fn private_function() { } #[test] fn test_private_function() { private_function() } </code></pre> <p>External tests, such as <code>tests/*.rs</code> and <code>examples/*.rs</code> if you’re using Cargo, or doc tests, do not get access to private members; nor should they: such tests are designed to be public API tests, not to be dealing with implementation details.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/27978377/How%20do%20I%20test%20private%20methods%20in%20Rust?/27978706">Stack Overflow</a>.</p>
comments powered by Disqus