Trending

#RustTesting

Latest posts tagged with #RustTesting on Bluesky

Latest Top
Trending

Posts tagged #RustTesting

#[cfg(test)] mod tests {     use std::thread;     use std::time::Duration;      #[test]     fn quick_test() {         assert_eq!(2 + 2, 4);     }      #[test]     #[ignore]     fn slow_test() {         // Simulate a long-running test         thread::sleep(Duration::from_secs(5));         assert!(true);     } }

#[cfg(test)] mod tests { use std::thread; use std::time::Duration; #[test] fn quick_test() { assert_eq!(2 + 2, 4); } #[test] #[ignore] fn slow_test() { // Simulate a long-running test thread::sleep(Duration::from_secs(5)); assert!(true); } }

🧪 #Rustlang Tip: Use #[test] with #[ignore] for long-running or resource-intensive tests.

Run all tests: cargo test
Run ignored tests: cargo test -- --ignored

This helps keep your test suite fast while still allowing those long running tests when needed!

#RustTesting #Rust30by30 #Day15

3 0 0 0
fn fibonacci(n: u64) -> u64 {     if n <= 1 {         return n;     }     fibonacci(n - 1) + fibonacci(n - 2) }  #[cfg(test)] mod tests {     use super::*;      #[test]     fn test_fibonacci() {         assert_eq!(fibonacci(0), 0);         assert_eq!(fibonacci(1), 1);         assert_eq!(fibonacci(2), 1);         assert_eq!(fibonacci(10), 55);     } }

fn fibonacci(n: u64) -> u64 { if n <= 1 { return n; } fibonacci(n - 1) + fibonacci(n - 2) } #[cfg(test)] mod tests { use super::*; #[test] fn test_fibonacci() { assert_eq!(fibonacci(0), 0); assert_eq!(fibonacci(1), 1); assert_eq!(fibonacci(2), 1); assert_eq!(fibonacci(10), 55); } }

🧪 #RustLang Tip

✅ DO: Use Rust's built-in testing framework to write unit tests and integration tests.
❌ DON'T: Skip testing, it's crucial for maintainable code! #RustTesting #TDD

Run `cargo test` to see the output!
Learn more: https://buff.ly/3XZHtbu

#Rust30by30 #Day3

0 0 0 0