Closed glarimy closed 6 years ago
Complete this activity by CoB tomorrow and check-in the code.
Checked the code of junit sir
Thanks!
Develop the unit testcases for the following scenarios and check-in the code.
Complete this by CoB today and check-in the code.
To give a reference, here is the implementation for the first case:
The call to getCurrentScore() immediately after instantiating SimpleScoringService must return a score with 0 numberOfAttempts and 0 numberOfPoints.
@RunWith(AndroidJUnit4.class)
class SimpleScoringServiceTest {
@test
public void testInitialScore() {
ScoringService service = new SimpleScoringService();
Score score = service.getCurrentScore();
assertTrue("invalid initial attempts", score.getNumberOfAttempted == 0);
assertTrue("invalid initial points", score.getNumberOfPoints == 0);
}
}
Keep this class under androidTest/java/com/glarimy/quiz/service package Hope this helps!
sir i have gone through the test case send by you but it is showing null pointer exception for score.getNumberofPoints and score.getNumberofAttempted in testInitialScore() but evaluate and getcurrentscore test cases are working fine. Can you guide me to find the null pointer exception case
A test case verifies the correctness of the target code. Here the target code is SimpleScoringService and test case is SimpleScoringServiceTest. If the test case succeeds, it means the target code is correct. If the test case fails, the target code is incorrect.
Proven software engineering process suggests the following process:
In your case, the SimpleScoringService.getCurrentScore() seems to be returning null (because of the stub implementation). You can do this:
@RunWith(AndroidJUnit4.class) class SimpleScoringServiceTest {
@Test
public void testInitialScore() {
ScoringService service = new SimpleScoringService();
Score score = service.getCurrentScore();
assertTrue("invalid score returned", score != null);
assertTrue("invalid initial attempts", score.getNumberOfAttempted == 0);
assertTrue("invalid initial points", score.getNumberOfPoints == 0);
}
}
When you run this test case against the target code (with stub implementation), the test case fail, but you do not get null pointer exception. When you run the test case against the target code (with real implementation), the test case must pass. If it fails, there is problem in the target code.
Remember, the illustrations I am giving are only for reference. You need to thing through and adjust it to your actual scenarios.
executed test cases successfully and checked in the code
Thanks
Develop JUnit test cases for SimpleScoringService.