
Testing
Unit tests, integration tests, doc tests, assertions, should_panic, benchmarks, test organization
1Which attribute marks a function as a unit test in Rust?
Which attribute marks a function as a unit test in Rust?
Resposta
The #[test] attribute tells the Rust compiler that the annotated function is a unit test. When running cargo test, all functions marked with this attribute are automatically discovered and executed. Tests are compiled only with the test profile and are not included in the production binary.
2Which Cargo command runs all tests in a Rust project?
Which Cargo command runs all tests in a Rust project?
Resposta
The cargo test command compiles the project with tests enabled and runs all unit tests, integration tests, and documentation tests. It automatically discovers functions marked with #[test], tests in the tests/ directory, and code examples in documentation. Options allow filtering tests by name or module.
3Which macro should be used to check that two values are equal in a test?
Which macro should be used to check that two values are equal in a test?
Resposta
The assert_eq! macro compares two values and fails the test if they are not equal. It automatically displays the compared values on failure thanks to the Debug trait, making debugging easier. Unlike assert!, it provides a more informative error message showing the expected value and the actual value.
Where should integration tests be placed in a Rust project?
Which attribute should be used to test that a function causes a panic?
+15 perguntas de entrevista
Outros temas de entrevista Rust
Rust Basics
Ownership & Borrowing
Structs & Enums
Error Handling
Collections
Modules & Packages
Traits
Generics
Lifetimes
Iterators & Closures
Smart Pointers
Concurrency Basics
async/await
Cargo & Ecosystem
Pattern Matching
Macros
Serde & Serialization
Unsafe Rust
Advanced Traits
Advanced Lifetimes
Type System
Tokio & Async I/O
Performance Optimization
Memory Management
Web Frameworks
Database Integration
Rust Design Patterns
Domine Rust para sua proxima entrevista
Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.
Comece gratis