Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>As a Rust newbie, I only wish there were better examples of testing in public Rust repos.

Testing is incredibly easy. The reason you may have missed the testing is that tests are often in the same file as tested code. Go back and check, it's very common in Rust to test your code. And it's as simple as writing:

  #[test]
on the line before your unit test function, and then using some of the unit test macros in std like `assert` and `assert_eq` along with `fail` to perform the tests[1].

Then you test your code by running the normal rustc command but with the `--test` flag. A test runner with very attractive output is built into the compiler.

Rust unit testing is just about the easiest testing I've ever used, right up there with golang. I love that it's built into the language.

Also, the `cargo` package manager makes everything -- including unit testing -- incredibly convenient. And I say this as someone who cringes every time a language comes out with yet another package manager or build tool (ahem, .js). But in the case of rust's cargo, it's incredibly worth it to use a new package manager, and so much better than a Makefile (although it's quite easy to integrate makesfiles with cargo).

1. http://doc.rust-lang.org/std/index.html



The guide has a whole section on this: http://doc.rust-lang.org/guide.html#testing

And we even have a full guide on testing, though I haven't checked it lately: http://doc.rust-lang.org/guide-testing.html (it's on the todo list)


One of the huge wins of rust is that the devs put a lot of effort into its basic infrastructure. Testing, documenting, and benchmarking are almost too easy.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: