Unit testing a functions whose purposes is side effects

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-05-06T16:23:58Z Indexed on 2010/05/06 16:28 UTC
Read the original article Hit count: 146

Filed under:
|

How would you unit test do_int_to_string_conversion?

#include <string>
#include <iostream>

void do_int_to_string_conversion(int i, std::string& s) {
    switch(i) {
    case 1:
        s="1";
        break;
    case 2:
        s="2";
        break;
    default:
        s ="Nix";
    }
    std::cout << s << "\n";
}

int main(int argc, char** argv){
    std::string little_s;

    do_int_to_string_conversion(1, little_s);
    do_int_to_string_conversion(2, little_s);
    do_int_to_string_conversion(3, little_s);

}

© Stack Overflow or respective owner

Related posts about c++

Related posts about unit-testing