ASH84

Software Engineer/Developer, co-founder of Payhere. Ex-Banksalad. Intereseted in iteroperability, bootstrap company, writting.

Rust-DAY2

created:2020-01-28
updated:2020-01-28
edit

TestCase 를 작성해보자. #2

    ├── Cargo.lock
    ├── Cargo.toml
    ├── Makefile
    ├── README.md
    ├── resource
    │   └── host.yaml
    └── src
        ├── arg.rs
        ├── config.rs 
        ├── main.rs
        └── misc.rs
        // src/lib.rs
        pub mod arg;
        pub mod config;
        pub mod misc;

        // tests/test_arg.rs
        #[cfg(test)]
        mod test {
            use sun::arg::parse_arg;
            ...

왜 내 프로젝트엔 lib.rs 가 없었을까?

    --bin      Use a binary (application) template [default]
    --lib      Use a library template

panic! 테스트 하기

        fs::read_to_string(file_name).expect("no file");

        #[test]
        #[should_panic]
        fn test_load_yaml_abnormal_path() {
            load_yaml(String::from("test"));
        }

테스트 코드에서는 [should_panic] 을 적어주면 된다.

기타

References


#testcase  #rust  #100DaysOfRust  #panic