glarimy / glarimy-quiz-app

The source code and resources for Glarimy Quiz community project
0 stars 0 forks source link

Unit test GlarimyQuestionService #32

Closed glarimy closed 6 years ago

glarimy commented 6 years ago

Develop unit test cases for the following and check-in the code.

  1. The get() method must return a question. The question id must be non-zero, the description must be a non-empty string, all the options must be non-empty strings.
  2. Two subsequent calls to get() method must return two questions with different ids.
  3. The get() method must return null, if there is no network connectivity.
  4. The getAnswer() method must return null if the answer id is a negative number.
  5. The getAnswer() method must return null if there is no network connectivity.
  6. The getAnswer() method must return an answer. The answer.questionId and argument passed to the method must be same. The answer.correctOption value must be between 1 and 4. The answer.tickedOption value must be 0.
  7. The isConnected() method must return false if there is no network connection.

Complete the task by CoB today.

ramakrishna5a1 commented 6 years ago

sir i am understand the test cases what the input to be given and what the expected output to be .but no idea on getting how to write the test cases in the form of coding.i am tried by revising some tutorials but no result.sir please give me a small explanation regarding the coding of test cases

glarimy commented 6 years ago

Here is the implementation for the first case:

The get() method must return a question. The question id must be non-zero, the description must be a non-empty string, all the options must be non-empty strings.

@RunWith(AndroidJUnit4.class) class GlarimyQuestionServiceTest { Context appContext = InstrumentationRegistry.getTargetContext(); @Test public void testQuestion() { QuestionService service = new GlarimyQuestionService(appContext);

    if (service.isConntected) {
         Question question = service.get();
         assertTrue("Invalid question is returned", question != null);
         assertTrue("Invalid question id is returned", question.getId() >= 0);
         assertTrue("Invalid question description is returned", question.getDescription() != null);
         assertTrue("empty question description is returned", question.getDescription().trim().length != 0);
         assertTrue("Invalid first option is returned", question.getOptionOne() != null);
         assertTrue("empty first option is returned", question.getOptionOne().trim().length != 0);
         // and so on ...
   }else{
         Question question = service.get();
         assertTrue("Question available without connection", question == null)
   }

}

Keep this class under androidTest/java/com/glarimy/quiz/service package Hope this helps!

ramakrishna5a1 commented 6 years ago

thank you sir it will be helped to me to get the idea on test case coding.

ramakrishna5a1 commented 6 years ago

sir when i am running the test case it is giving the following result

Process finished with exit code 1 Class not found: "com.glarimy.quiz.service.GlarimyQuestionServiceTest"Empty test suite.

i am still searching solution for this problem sir if any solution please suggest me.

glarimy commented 6 years ago

Any update on this?

ramakrishna5a1 commented 6 years ago

Currently working on this sir