Lev's blog

Not TDD

Sometimes when I'm learning a new library, I write a test. In Rust, this is as easy as:

#[cfg(test)]
mod test {
    use csv::*;
    
    #[test]
    fn test_csv() {
        let mut reader = ReaderBuilder::new()
            .has_headers(false)
            .from_reader("one,two,three".as_bytes());

        let row = reader
            .records() // get a records reader
            .next() // read a record
            .unwrap() // panic if there aren't any
            .unwrap(); // panic if the record is not valid CSV

        assert_eq!(row.get(0), Some("one"));
    }
}

Why? This teaches me how the crate works, without spending brain cycles on trying to fit it into my app. Doing two things at once is hard, especially when one of them is new.

This code isn't wasted. In fact, you should keep it. It'll run in your test suite and ensure the library continues to work when it's upgraded.

I don't think this is test-driven development. This is just writing tests.