In JUnit 4 (which is the version that was shown in class), which of the followin
ID: 3549819 • Letter: I
Question
In JUnit 4 (which is the version that was shown in class), which of the following code fragments could be part of the declaration of a test called testName?
In JUnit 4 (which is the version shown in class), which of the following code fragments must be part of the declaration of a test called testName?
Question 1 of 5Each unit test's purpose is to A. Validate that (part of) the program meets the users' needs B. Verify that (part of) a single method works C. Verify that the entire program works D. Make sure that you correctly converted between feet and meters. Reset Selection
Question 2 of 5
You should usually write less testing code than implementation code. True False Reset Selection
Question 3 of 5
In JUnit 4 (which is the version that was shown in class), which of the following code fragments could be part of the declaration of a test called testName?
A. int testName( B. testName() C. timeout=100 D. public E. private F. @Test G. expected=NullPointerException.class H. void testName( I. boolean testName(Question 4 of 5
In JUnit 4 (which is the version shown in class), which of the following code fragments must be part of the declaration of a test called testName?
A. expected=NullPointerException.class B. public C. timeout=100 D. testName() E. @Test F. boolean testName( G. testName(int x) H. void testName( I. int testName(Question 5 of 5
Of the following, which is the best advice? A. Don't write tests; if you code carefully you can be confident you have succeeded B. Write a single test that only pases if the whole program works C. Write one test per method, each testing all of that method's functionality D. Write many tests for each method, each testing only a single aspect of the method's functionality Reset Selection
Explanation / Answer
1.B. Verify that (part of) a single method works
Reason - Each test checks one method or a part of method. That is why it is named unit test
2. False
Reason - Number of test cases should be more than the real code. it ll lessen the chances of failure. the more number of test cases, more secure is ur code.
3. void testName(
Reason - A test case should never return anything. Even if the real method return anything. So return type should be void. And by convention one keeps same name of the test method as the real method.
4. @Test
Unless u have this annotation on top of each test case, you can not run the test cases and you can not map to the real method. It ll give an error saying no test case scenario defined.So @Test annotation is a must.
5. Write many tests for each method, each testing only a single aspect of the method's functionality
Reason - There can be many if else and other logics. Assume, in one case, your code goes inside if block, so it ll leave the else block. In that case, the functionality of else block is not checked. and what if the else block code is errorprone. Again if there is a switch, then just one case can be checked, not all of it. So it is always better to have many tests for each method
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.