Skip to main content

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

Popular posts from this blog

Coding solutions - Amazon card, Data structure, Search and Sort

  Amazon card, Data structure, search and sort Hashmap # HASH MAP implementation in python class Node :     def __init__ (self, key, value) :         self.key = key         self.value = value         self.next = None class HashMap :     def __init__ (self) :         self.store = [ None for _ in range( 16 )]     def get (self, key) :         index = hash(key) & 15         if self.store[index] is None :             return None         n = self.store[index]         while True :             if n.key == key:                 return n.value             else :                 if n.next:         ...

Debugging round interview questions

Debugging round interview questions with answers. These are real questions asked in real interviews.  1. When you come in the morning, SLA has increased for the job searching portal (website). It was fine till today morning. How are you going to debug it? There is a matrix that shows service and it’s SLA. What are the steps you are going to take to debug this problem? Answer : If the SLA has gone up suddenly it's definitely a critical issue. I will first report this problem to all stakeholders. I will check listed points to debug the problem - 1. Check what went in the latest release if that is one  2. Check for nodes that are down. If there is an unusual number of nodes that are not reachable then report it to the infrastructure team. 3. Check for database repair which can cause slowness 4. Check its client-side delay or server-side delay to narrow down the issue 5. Check the geolocation of where the website is slow in order to narrow down 6. Check network bandwidth in the da...

Coding round interview questions tips

Tips from the google coding interview video https://www.youtube.com/watch?v=XKu_SEDAykw Always ask for clarifications - some tips below Think out loud Talk about all the solutions before you code out Test a few inputs after writing code by tracing it before saying I am done Talk while coding Talk about time and space complexity at the end to get bonus points Read out the problem loud in a way you understood - Do not code out the wrong solution Clarifying questions Clarify the input & output. E.x. This function accepts 2 arrays and returns an integer, Am I right? Sorting - array already sorted, reverse sorted or not sorted? Can there be -ve elements? Can there be only integers or other types? String - other than English? Can it contain special chars, Unicode, upper case and lower case letters? https://medium.com/@mgtei/how-why-to-ask-clarifying-questions-at-a-whiteboard-interview-for-junior-devs-97571fdc629e Key point to succeed in this round is just don't give up on the problem...