GN Rules for Rust Tests

The simplest way to build Rust gtest tests is to add them to an existing test binary that already contains tests authored in C++. For example:

  1. test("ui_base_unittests") {
  2. ...
  3. sources += [ "my_rust_lib_unittest.rs" ]
  4. deps += [ ":my_rust_lib" ]
  5. }

Authoring Rust tests in a separate static_library also works, but requires manually declaring the dependency on the support libraries:

  1. rust_static_library("my_rust_lib_unittests") {
  2. testonly = true
  3. is_gtest_unittests = true
  4. crate_root = "my_rust_lib_unittest.rs"
  5. sources = [ "my_rust_lib_unittest.rs" ]
  6. deps = [
  7. ":my_rust_lib",
  8. "//testing/rust_gtest_interop",
  9. ]
  10. }
  11. test("ui_base_unittests") {
  12. ...
  13. deps += [ ":my_rust_lib_unittests" ]
  14. }