During white box testing which conditions have to be tested?

Consider a post request with integer data. In the function, I will convert that post data (string type) to an integer type. I am using python int() function and hence 'int' will produce value error for an alphabetical valuye and Type error for data other than string and integer.

In the front end, that is in HTML, the user can enter only integer data which is achieved by HTML tags.

Is it necessary to test the statement in white box tests with conditions that produce type and value error?

1 Answer 1



The HTML might prevent users entering invalid data, but that does not mean they can't bypass this easily. As a general rule you should always validate user input twice: once at the client, and again at the server.

Tools like Postman, Fiddler, and the like will allow someone to capture the information in your form and manipulate the Post request to send other data. If you aren't properly handling invalid data, that can leave your application vulnerable to security issues.

Your unit tests should test:

  • each class of valid input
  • expected invalid input (such as integers outside the expected range)
  • other invalid input (such as alphabetical input, doubles, booleans, dates, system commands... the list is endless)

Your code should have robust error handling and return some kind of error message with the stack dump. You should be logging the stack dump, and returning a simple error message to the user.

  • Kate’s comments are all good pieces of advice, though i’d like to add you ought to turn this into a data driven test. With a data driven test, you only need to maintain one request. Wrap this in a loop and pass in the parameters and expected results for the specific test. That way you only need to maintain one request and to add additional test cases, you just add extra lines to your test data. Commented Oct 20, 2017 at 9:30
  • Am i need to check int() for all possible values of errors that can raise? Here Value Error can cause due to alphabets and same can be due to float values. So am i required to test for alphabet and float numbers?
    – vishnu m c
    Commented Oct 20, 2017 at 9:32
  • 1
    Use equivalence partitioning, separate your range to logical parts and choose one value from each. E.g. negative, zero, positive
    – Rsf
    Commented Oct 20, 2017 at 11:00
  • @Rsf Sorry, i didn't get that. If ValueError is arised for alphabet and float numbers, should i check for both? I think, we are concerned about handling of error, i think we need to take only either of the condition alphabets or float numbers since both produce same result. Am i right?
    – vishnu m c
    Commented Oct 23, 2017 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.