Goals and objective of unit test:
Unit test are done to check whether a particular module or unit of code is working fine. It eliminates all logical and runtime errors. It is particularly useful for testing code at the most basic module to ensure any errors don’t percolate up to the modules up in the hierarchy. A main objective of unit testing is to achieve 100% code and data coverages.
100% code coverage is achieved by analyzing expectations of individual methods and producing test cases to meet each of those requirements. Actual implementation of code can also taken into account to achieve more code coverage. Exception handling is also covered in this part.
For data coverage, we take all extreme end values (INT_MAX,INT_MIN) and boundary values for testing as results for rest of the values are identical.
One instance of typical data values can be taken as results don’t vary for rest values. Illegal data values/null/empty are also tested to check if code rejects them as expected. We would only stop when at least one instance of all kinds of data values has been included in our test set. Uninitialised values are tested for their default values, like an uninitialized integer is tested for a zero value.
In case of exception testing, a test case is of form “testMethodNameException”
In case of attribute checking, test case is of form “testMethodNameAttr_AttrName”
These naming conventions help us to clearly see which method and attribute of the method is being tested just by looking at the test name.
Each test method would be a single test case, so that we clearly know which test value fails.
And there should be a single assert per method. This is because when an assert fails, we don’t have many choices in front of us to decide which one failed. There should be at least one assert/fail statement in each method else test case would not ever fail. Also, there can be multiple fail statements within a method, unlike assert. All test case methods match actual declaration in code.
How do you know you are done testing? :
When you have supplied all possible inputs that a module can take and the module shows the expected results. Often an important subset of all possXXXX inputs XX XXXXX to XXXX time and run unit XXXXX in XXXXXXXXXX time. All corner cases XXX boundary XXXXXX must XXXX be included in test XXXX.
What kind XX testing is XXXX XXXX (black-XXX, XXXXX-box, boundary, etc.) XXX make sure XX explain what that type of XXXXXXX does?
Black box testing XX XXXX when XXXX XXX XXXXXX XX XXXXXXX XXXX is XXXXX tested. XXX internal structure of code XX XXX taken XXXX account. XXXXX box testing XX done when you XXXX XX check the internal XXXXXXXXX/methods as XXXX. The entire XXXX structure and XXX local/XXXXXX XXXXXXXXX and XXXXXXX XXX taken XXXX XXXXXXX and XXXXXXXX.
XXXX testing XXX be done in XXXX the ways.
What XXX code XXXXXXXX XXX XXXX XXXXXXXX and how they XXXXXX XX unit test?
XXXX coverage XXXXXX to XXX XXXXX/blocks of code being XXXXXXXXX by XXXXXXXXXX XXXX XXX. XXXX coverage refers to the span XX test data that XX are able to XXXXX XX XXXXXXXXX a XXXXXXXXXX test XXX.
With reference XX XXXX test, XX must maximize both XXXX XXXXXXXX XXX XXXX coverage. XXX% XXXX XXXXXXXX is often not possible so we XXXX XXXXXXXX our test data to XXXX increasing data coverage XXXXX XXXXXXX in mind a XXXXXXXXXX XXXXXXX XXX the XXXXX.
What XXX XXXX characteristics that you learned about in XXXX X of XXXX course? Name XXXX and XXXXXXX in your own XXXXX:
The XXXX XXXX XXXXXXXXXXXXXXX XXXXXXX in XXXX 3 XXX as XXXXXXX:
Fast: XXXX tests should XX able to run quickly.Independent: Unit XXXXX should be separate from one another. This allows them XX be run in any order.XXXXXXXXXX: Unit XXXXX XXXXXX XX able XX XX repeated in XXX XXXXXXXXXXX.Self-XXXXXXXXXX: Units tests XXXXXX XXXXXX XXXX XXXX or pass.Timely: XXX XXXX tests XXXXXX not take an XXXXXXXX XXXXXX of time to write.XXXXXXXXX: XXXX XXXXX XXXXXX XX able XX run automatically. You XXXXXX be able to type in XXX XXXXXXX or simply hit a button and run XXX XXXXX. XXXX also means XXXX the test should be able to determine, on its own XX it has failed or XXXXXX. You XXXXXX not XXXX to read through some long output XX figure out XX it XXXXXX or XXX.XXXXXXXX: This XXXXXX means XXXX a unit XXXX XXXXXX test XXXXXXXX that you XXXXXXX XX XXXXX XX XXXXX. If you think it XXXXX go XXXXX: test it. XX XXXXXX, you XXX’t always XXXX XXXXXXXXXX XXXXXXXXXX, so you XXXX XXX XXXX XXXXXXXXX XXXXX XX your project’s XXXXX.Repeatable: XXX tests XXXXXX XX able XX run XXXX XXX XXXX in any order XXXXXX XXX end up XXXX XXX same XXXXXXX. Unit XXXXX XXXXXX essentially XX independent XX environment. XXXXX this will allow you XX repeat the XXXX XXXX in any environment XXXXXXX issue.XXXXXXXXXXX: XXXX tests need XX XX kept independent from XXX another. XXXX means XXXX XXXXX XXXXXX XXX XXXX to rely on XXXXXXX in order XX run. XXXX should also be independent of XXX XXXXXXXXXXX. This allows them XX run XXX unit XXXXX XXXXXXXX XXXXXX. XX’s also possible that other XXXXXXXXXX XXX need to run XXX XXXXX XX XXX same XXXX, so XXXXXXXXXXXX XX important.XXXXXXXXXXXX: XXXX means that the unit tests you write XXXXXX XXXXXX XX XXX XXXX standards XX your production XXXX. You XXXXXX XXXXX the XXXX XXXXXXXXXX XX XXXX design XXX XXXXX code to the XXXX XXXXX.
Who normally XXXXXX XXX executes XXXX XXXX?
XXXXX box unit XXXXXXX is XXXX by developers XXXXXXXXXX. XXXXXXX XXXXX XXX unit XXXXXXX can be XXXX by separate XXXXXXX. XXXX often both XXX testing is done XX XXX XXXXXXXXXX themselves.
XXX XX you XXXXXXXXX XXXX a XXXXXX XXX XXXX XXXXX in XX?
XXXXXXXX, XXXXXXX XXXXXXXXX statements are used XX perform XXXXXXX. XXXXXXX XX assertion XX XXXXXXXX in logs whenever XXX such XXXXXXXXX fails. XXXX generated XXXXX running XXX tests XXXXXX be XXXXXXXXX examined.
XX XXXXXXX XXX found during unit test XXX then XXXXX them?
The test XXXXXXX XXX XXXXXXXX back XX the XXXXXXXXXX (in XXXX someone else did XXX testing) Proper conditions XXX corner-case XXXXXX are XXXXXX in XXX code XX XXXXXX the XXXX XXXXXXXXXXX.
What XXXXXXX XXXX after XXXXXX is fixed in XXX XXXX being XXXXXX?
Once XXX XXXX XX fixed XXX unit XXXXX XXX re-XXX, if XXXXX XX any XXXXXXXXXXX code changes XXXXX fixing XXX bug, XX XXXX incorporate XXXX test XXXXX in our test XXXX XX XXXXXXX XXXXXXXX the code coverage.
1.X
XXX% Code XXXXXXXX XXXX Cases
X.2.1 XXXX XXXX X
XXXX case name: testDefaultConstructorAttr_CurrentFunc
XXXXXX being tested: MultiFunctionPrinter()
Short Description: check XX XXXXXXXXXXX is XXXXX initialized XX XXXXX XX object XXXXXXXX
XXXXX Data XX constructor and/or XXXXXX you XXX XXXXXXX: no inputs
XXXXXXXX XXXXXXX: attribute currentFunc XXXX value PRINT
1.X.2 Test XXXX X
XXXX XXXX XXXX: testGetFunction
Method XXXXX XXXXXX: XXXXXXXXXXX()
XXXXX XXXXXXXXXXX: check XX we XXX XXXXXXXX correct XXXXX of attribute XXXXXXXXXXX
Input Data XX XXXXXXXXXXX XXX/or method you XXX XXXXXXX: no inputs
XXXXXXXX XXXXXXX: XXXXXXXXXXX returns XXX XXXXX XX attribute currentFunc XXXXX XX XXXXX
X.X.3 Test XXXX 3
Test XXXX name: XXXXXXXXXXXX
Method XXXXX tested:getPages()
Short XXXXXXXXXXX: checks XXXXXXX XX XXX retrieve correct value XX pages
XXXXX XXXX to XXXXXXXXXXX XXX/or method you are testing:no XXXXXX (XX XXXXX XXXX XXXX XXXX XXXXXXXXXXX XX XXXX, so we XXXX XXXXX that)
XXXXXXXX Results: getPages() XXXXXXX XXX XXXXX XX XXXXXXXXX XXXXX equal XX zero
1.2.X Test XXXX 4
XXXX case XXXX: testSetFunctionException
XXXXXX being tested:setFunction(Function f)
XXXXX XXXXXXXXXXX: to XXXXX XX the XXXXXXXX throws an XXXXXXXXXXXXXXXXXXXXXXXX when XXXXXX function is not XXXXX XX XXXXX/SCAN
XXXXX XXXX XX XXXXXXXXXXX XXX/or XXXXXX you XXX testing:f=FAX
Expected XXXXXXX: XXXXXXXXXXX(XXXXXXXX f) should throw an XXXXXXXXXXXXXXXXXXXXXXXX
1.X.X XXXX XXXX X
Test case XXXX: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Method being XXXXXX:XXXXXXXXXXX(Function f)
Short XXXXXXXXXXX: to XXXXX XX XXX XXXXXXXX correctly assigns XXX value XXXXXXXXXXX = f
XXXXX Data XX XXXXXXXXXXX and/or method you are XXXXXXX:f=PRINT
XXXXXXXX Results: XXXXXXXXXXX(Function f) should set value of XXXXXXXXXXXX=XXXXX
X.2.6 Test Case X
XXXX case XXXX: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXX being XXXXXX:XXXXXXXX(int p)
XXXXX Description: to XXXXX XX XXX function currently assigns attribute XXXXX=0 when XXXXXX XXXXXXXXX p<0
XXXXX Data to XXXXXXXXXXX and/or XXXXXX you are XXXXXXX:p= -XX
Expected XXXXXXX: XXXXXXXXX XXXXX of XXXXX XX XXX XX X
1.X.7 XXXX Case X
XXXX case name: testSetPagesAttrPages_whenParameterIsNonNegative
XXXXXX being XXXXXX:setPages(XXX p)
XXXXX Description: to check XX the XXXXXXXX XXXXXXXXX XXXXXXX XXXXXXXXX XXXXX=p when XXXXXX XXXXXXXXX XX not negative
Input XXXX XX constructor XXX/or method you are XXXXXXX:p=X
Expected Results: XXXXXXXXX XXXXX XX pages XX set to 0
X.X.8 Test Case X
XXXX case name: testSettingsException
XXXXXX being XXXXXX:XXXXXXXX(XXXXXXXX f, int p)
Short XXXXXXXXXXX: XX XXXXX XX settings XXXXXX XXXXXX appropriate XXXXXXXXX XXXX f is XXX COPY/XXXXX
XXXXX Data to XXXXXXXXXXX and/or method you XXX testing:f=FAX,p=X
Expected Results: settings method XXXXXX IllegalArgumentException
X.X.X XXXX XXXX X
Test case name: testSettingsAttr_pages
Method XXXXX tested:settings(XXXXXXXX f, XXX p)
Short Description: XX XXXXX XX settings XXXXXX correctly assigns pages = p
Input XXXX to XXXXXXXXXXX and/or method you XXX testing:f=COPY,p=X
XXXXXXXX XXXXXXX: should XXX XXXXXXXXX XXXXX XX X
X.2.10 XXXX Case 10
Test case XXXX: XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Method XXXXX XXXXXX:settings(Function f, XXX p)
Short XXXXXXXXXXX: to XXXXX if settings XXXXXX correctly XXXXXXX XXXXXXXXXXX = f
Input Data to XXXXXXXXXXX and/or method you XXX XXXXXXX:f=COPY,p=X
XXXXXXXX Results: should XXX attribute currentFunc XX XXXX
X.3 XXXXXXXXXX Test Cases XXX Data Coverage
1.3.1 XXXX Case 1
Test XXXX name:
Method being tested:
XXXXX XXXXXXXXXXX:
XXXXX XXXX to constructor and/or XXXXXX you are testing:
Expected Results:
X.X.X Test Case 2
XXXX case XXXX:
Method XXXXX XXXXXX:
XXXXX Description:
Input XXXX to constructor XXX/or XXXXXX you are XXXXXXX:
Expected XXXXXXX:
X.3.3 Test XXXX 3
XXXX XXXX XXXX:
XXXXXX XXXXX XXXXXX:
XXXXX Description:
Input Data to constructor XXX/or XXXXXX you XXX testing:
XXXXXXXX Results:
…
X.
Defects
This XXXXXXX XXXXX XXX XXXXXXXXXX XXXXXXX
2.1
XXXXXXX
X.X.1
XXXXXX X
XXXXXX/XXXXXXXXXXX:Put here XXX XXXXXX method or XXXXXXXXXXX XXXX that XXX a defect
Defect Description: XXX here, what XXXXXXXX XX incorrect and XXX you XXXXXXX it’s a XXXXXX. XXXX XXX XXXXXXXX XXXXXX actual behavior?
How Found:Explain how you were able to find this defect XXX XXXXX XXXX case (XXXX of XXXXXXXX) found the issue
2.X.2 Defect 2
XXXXXX/XXXXXXXXXXX:Put here the source method or XXXXXXXXXXX XXXX XXXX XXX a defect
Defect Description: XXX here, what XXXXXXXX XX XXXXXXXXX and why you believe it’s a XXXXXX. What was XXXXXXXX versus XXXXXX behavior?
How Found:Explain how you XXXX able XX find this XXXXXX XXX XXXXX test case (XXXX of XXXXXXXX) XXXXX the issue
.…
X.
Other
Sources:
XXXXX tutorials:https://www.tutorialspoint.com/XXXXX/XXXXX.XXXJUnit XXXXXX by XXXXXXXXXXX:https://XXX.youtube.com/watch?v=XXXXXXXXXXXCode coverage :XXXX://tutorials.jenkov.XXX/java-unit-XXXXXXX/XXXX-XXXXXXXX.XXXXXXXX XXXXXXXX overview:XXXXX://glebbahmutov.XXX/blog/data-coverage/
X.X
XXX
X.X
YYY
">