Unit Testing

Discussion to talk about software related topics only.
Post Reply
crypt
Posts: 1
Joined: Mon Jul 02, 2012 8:41 am

Unit Testing

Post 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.
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Unit Testing

Post 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.
Post Reply