Page 1 of 1

Unit Testing

Posted: Mon Jul 02, 2012 8:53 am
by crypt
I'm currently setting up some unit tests for our NetBurner code using a Java based connection. I have this piece of code, that I'd like to test a failure on.

Code: Select all

int read_amount = read(fd_Network, network_buffer, FD_BUFFER_SIZE-1);

writeall(fd_Serial, network_buffer, read_amount);
iosys.h says that the read() function will return a negative number on failure.

Is there an easy way of creating a failure with read()?

edit: took away statement about maybe causing an error in writeall() after looking at code.

Re: Unit Testing

Posted: Mon Jul 02, 2012 1:51 pm
by tod
I'm not just trying to be pedantic but what you are proposing is not a unit test, it is more of an integration test. If you are trying to satisfy a unit testing coverage requirement you will probably need to insert a testing seam into the code. If you don't care about the distinction, then one way to force read to fail would be to use an invalid file descriptor for fd_Network. The error returned should be TCP_ERR_NOSUCH_SOCKET which is -4.

Without capturing the return value of writeall() it might be tough to write a good test.