Test data generation or Unit testing interview questions

 



Some useful info about how to do unit testing-
Unit testing is done by developers in an early development stage. Uncovering bugs early saves time and cost. An individual unit of the software is tested by isolating it.

Tips and examples- 

1. The question could be asked as writing unit tests or writing test data for a function
2. Remember to cover positive, input check, boundary, edge and corner cases

3. Unit tests format will look like this - 

Test 1:

i/p: None, None

o/p: None

Test 2:

i/p:

o/p:


4. Python unit test example -

Import pytest

Class TestAnagram(unittest.TestCase)

Def test_input(self):

Assert anagram(“cat”, “dog”) == False

Def test_valid(self)

Assert anagram(“cat”, “tac”) == True

Def test_error(self)

With pytest.raises(Exception)

anagram(None, None)


5. Test data format

  1. None, None

  2. None, “cat”

  3. “Cat”, None


Interview questions -
Q: find_second_largest_number(array) {} - I did not write the code, function like this was written on the board.
Write test data for the function which finds the second largest number in an input array.
Company: Amazon
1. Empty array
2. String, int, float etc other than an array 
3. Null or None 
4. Just one element
5. All elements equal
6. Second largest element as a first element
7. Second largest element as the last element
8. Second largest element appears before the largest element
9. Second largest element appears after the largest element
10. Second largest element is -ve
11. All elements -ve
12. 2nd largest = -3 and largest = 3

Q: This was asked with a coding question. Asked me to write code to find an intersection of two arrays and then write test data for it. a={1,2,3,4} b={3,4,6,7}
Company: Zenefits
1. Empty array
2. Null, None
3. Very huge array
4. None of the element intersects
5. All elements intersect 
6. First array is bigger than the second

7. Second array is bigger than the first


Comments