Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are these the sort of edge cases I should think of when using unit testing?

When writing unit tests, it is normally advisable to test the edge cases.

However, are these the right sort of things?

  • Test the connection to the db is not open (assert an exception is thrown)
  • Assert that a table, which must always have >1 row, does so
  • Assert that a field which is required, is != null.
  • Assert that an ip has been set in the right format (I can parse the string to IP).

Thanks

like image 589
GurdeepS Avatar asked Jan 17 '11 23:01

GurdeepS


People also ask

What are edge cases in unit testing?

Edge CasesThe situation where the test examines either the beginning or the end of a range, but not the middle, is called an edge case. In a simple, one-dimensional problem, the two edge cases should always be tested along with at least one internal point.

What is edge cases in testing with example?

An edge case is a problem or situation that occurs only at an extreme (maximum or minimum) operating parameter. For example, a stereo speaker might noticeably distort audio when played at maximum volume, even in the absence of any other extreme setting or condition. An edge case can be expected or unexpected.

How do you think of edge cases in programming?

Start by thinking about ways the code could fail and why. Make sure you understand the programming language and algorithms used. What are their weaknesses? Think on the extremes, think on different scales, different media, different use cases, think outside the box!

What are edge cases in software?

In software development, an edge case is a type of software bug that won't be a widespread issue. Instead, it only affects a small number of users, and devices, or can only be reproduced under uncommon circumstances. That doesn't necessarily mean that the bug is difficult to reproduce.


1 Answers

Your tests seem OK, but the phrase "edge case" normally refers to the tests and checks you need to do around the limits of the input.

Say you have a column in your database that can accept 50 characters. Your edge case tests are:

  • Save a string of 49 characters - success
  • Save a string of 50 characters - success (or perhaps failure because of the null termination character, depending on your language)
  • Save a string of 51 characters - failure

You can see that you are testing around and at the edges of your application where there are most likely to be errors. In this case there could be some confusion of the number of usable characters you can store which could cause errors in applications writing to your database.

Other tests where you would test saving a string of 20 characters and saving a string of 100 characters (say) should be done but these are going to be more stable.

like image 151
ChrisF Avatar answered Sep 25 '22 13:09

ChrisF