Testes no Android
Continuando em Testes, agora veremos como os testes unitĂĄrios funcionam no AOSP. Use o mĂłdulo rust_test
para seus testes unitĂĄrios:
testing/Android.bp:
rust_library {
name: "libleftpad",
crate_name: "leftpad",
srcs: ["src/lib.rs"],
}
rust_test {
name: "libleftpad_test",
crate_name: "leftpad_test",
srcs: ["src/lib.rs"],
host_supported: true,
test_suites: ["general-tests"],
}
testing/src/lib.rs:
Agora vocĂȘ pode executar o teste com
atest --host libleftpad_test
A saĂda se parece com isso:
INFO: Elapsed time: 2.666s, Critical Path: 2.40s
INFO: 3 processes: 2 internal, 1 linux-sandbox.
INFO: Build completed successfully, 3 total actions
//comprehensive-rust-android/testing:libleftpad_test_host PASSED in 2.3s
PASSED libleftpad_test.tests::long_string (0.0s)
PASSED libleftpad_test.tests::short_string (0.0s)
Test cases: finished with 2 passing and 0 failing out of 2 test cases
Observe como vocĂȘ menciona apenas a raiz da crate da biblioteca. Os testes sĂŁo encontrados recursivamente em mĂłdulos aninhados.