Rust Testing Quiz

Rust
0 Passed
0% acceptance

Master comprehensive testing strategies in Rust including unit tests, integration tests, documentation tests, and testing best practices

40 Questions
~80 minutes
1

Question 1

What is the basic structure of a Rust test?

A
#[test] fn test_name() { assert_eq!(expected, actual); }
B
test fn test_name() { ... }
C
fn test_name() #[test] { ... }
D
No specific structure
2

Question 2

Where should unit tests be placed?

A
In the same file as the code being tested, in a tests module
B
In separate test files
C
Anywhere in the codebase
D
Only in main.rs
3

Question 3

What does assert_eq!(a, b) do?

A
Panics if a != b, shows both values in error
B
Returns boolean
C
Prints values
D
assert_eq doesn't exist
4

Question 4

What is the difference between assert! and assert_eq!?

A
assert! takes one boolean, assert_eq! compares two values with better error messages
B
They are identical
C
assert_eq! is deprecated
D
No difference
5

Question 5

What does #[should_panic] do?

A
Test passes if function panics, useful for testing error conditions
B
Makes test panic
C
Ignores panics
D
should_panic doesn't exist
6

Question 6

What is integration testing in Rust?

A
Tests in tests/ directory that test public API as external users would
B
Tests inside lib.rs
C
Unit tests
D
No integration tests
7

Question 7

What are documentation tests?

A
Code examples in /// comments that are automatically tested
B
Tests in documentation
C
Manual documentation
D
Documentation tests don't exist
8

Question 8

How do you hide code from documentation tests?

A
Use # before lines to hide them from test execution
B
Use // to hide
C
Cannot hide code
D
Use #[doc(hidden)]
9

Question 9

What is the Result<(), Box<dyn Error>> pattern in tests?

A
Allows using ? operator in tests for cleaner error handling
B
Makes tests return results
C
Required for all tests
D
Not used in tests
10

Question 10

What does #[ignore] do?

A
Skips test unless run with --ignored flag
B
Deletes test
C
Makes test faster
D
ignore doesn't exist
11

Question 11

What is test organization best practice?

A
Arrange, Act, Assert pattern with descriptive test names
B
Random organization
C
No organization needed
D
Only one test per file
12

Question 12

What is a test fixture?

A
Setup code that runs before each test, like creating test data
B
Test framework
C
Test result
D
Test fixtures don't exist
13

Question 13

How do you test private functions?

A
Test through public interface, or make functions pub(crate) for testing
B
Cannot test private functions
C
Make all functions public
D
Use reflection
14

Question 14

What is mocking in Rust tests?

A
Replacing dependencies with test doubles using traits or conditional compilation
B
Making fun of code
C
Not possible in Rust
D
Built-in mocking
15

Question 15

What is property-based testing?

A
Testing with randomly generated inputs to find edge cases
B
Testing properties
C
Manual testing
D
Property-based testing doesn't exist
16

Question 16

What is fuzz testing?

A
Automated testing with malformed inputs to find crashes
B
Testing with random data
C
Performance testing
D
Fuzz testing doesn't exist
17

Question 17

What does cargo test --release do?

A
Runs tests with release optimizations, faster but may miss some debug checks
B
Makes tests release quality
C
Ignores tests
D
No such flag
18

Question 18

What is test-driven development (TDD)?

A
Writing tests first, then implementing code to pass tests
B
Testing after development
C
No testing
D
TDD doesn't exist
19

Question 19

What is code coverage?

A
Percentage of code lines executed during tests
B
Code quality metric
C
Test count
D
Code coverage doesn't exist
20

Question 20

What is continuous integration (CI) testing?

A
Automated testing on every code change in shared repository
B
Manual testing
C
One-time testing
D
CI doesn't exist
21

Question 21

What is benchmarking in Rust?

A
Measuring code performance using criterion or #[bench]
B
Testing correctness
C
Code coverage
D
Benchmarking doesn't exist
22

Question 22

What is the difference between black-box and white-box testing?

A
Black-box tests public interface without knowing internals, white-box uses internal knowledge
B
They are identical
C
Black-box is better
D
No difference
23

Question 23

What is test isolation?

A
Tests don't depend on each other or shared state
B
Tests run alone
C
Tests are isolated
D
Test isolation doesn't exist
24

Question 24

What is a flaky test?

A
Test that sometimes passes, sometimes fails due to race conditions or external dependencies
B
Fast test
C
Broken test
D
Flaky tests don't exist
25

Question 25

What is test double?

A
Generic term for mocks, stubs, fakes, spies used in testing
B
Two tests
C
Test framework
D
Test doubles don't exist
26

Question 26

What is a stub?

A
Test double that returns predetermined responses
B
Broken test
C
Test framework
D
Stubs don't exist
27

Question 27

What is a mock?

A
Test double that verifies interactions and can return different responses
B
Makes fun of code
C
Test framework
D
Mocks don't exist
28

Question 28

What is snapshot testing?

A
Comparing output against previously saved 'snapshots'
B
Taking screenshots
C
Performance testing
D
Snapshot testing doesn't exist
29

Question 29

What is contract testing?

A
Testing that APIs meet their contracts between services
B
Legal testing
C
API testing
D
Contract testing doesn't exist
30

Question 30

What is mutation testing?

A
Modifying code slightly to see if tests catch the changes
B
Changing tests
C
Performance testing
D
Mutation testing doesn't exist
31

Question 31

What is the testing pyramid?

A
Many unit tests, fewer integration tests, few end-to-end tests
B
Equal number of all test types
C
Only end-to-end tests
D
Testing pyramid doesn't exist
32

Question 32

What is end-to-end testing?

A
Testing complete user workflows through UI or API
B
Testing individual functions
C
Unit testing
D
End-to-end testing doesn't exist
33

Question 33

What is acceptance testing?

A
Testing that software meets business requirements
B
Code testing
C
Performance testing
D
Acceptance testing doesn't exist
34

Question 34

What is regression testing?

A
Re-running tests to ensure new changes don't break existing functionality
B
Testing regressions
C
Performance testing
D
Regression testing doesn't exist
35

Question 35

What is exploratory testing?

A
Manual testing without predefined script, discovering issues through exploration
B
Automated testing
C
Unit testing
D
Exploratory testing doesn't exist
36

Question 36

What is the main function in integration tests?

A
Each test file can have its own main function for setup
B
No main function needed
C
Must use lib.rs main
D
Main function not allowed
37

Question 37

What is doctest?

A
Running code examples from documentation as tests
B
Testing documentation
C
Manual testing
D
Doctest doesn't exist
38

Question 38

What is test parallelism in Rust?

A
Tests run in parallel by default for speed
B
Tests run sequentially
C
No parallelism
D
Parallelism doesn't exist
39

Question 39

What is test output capture?

A
By default, passing tests capture output, failing tests show it
B
All output is shown
C
No output capture
D
Output capture doesn't exist
40

Question 40

In a complex Rust project with multiple crates, async code, external dependencies, and performance requirements, what testing strategy would you implement?

A
Unit tests for pure functions, integration tests for APIs, async tests with tokio::test, mocks for external deps, benchmarks for performance
B
Only unit tests
C
Only integration tests
D
No testing strategy needed

QUIZZES IN Rust