(Note: If you are a Candidate attempting a HackerRank Test and looking for information about Test Cases in your Question, please refer to the Test Cases in your Coding Question topic.
If you are a recruiter using HackerRank for Work, refer this topic to understand the usage of Test cases while creating coding Questions for HackerRank Tests.)
What is a test case?
A test case is an input and output for a given programming question, allowing you to validate the candidate's code. When your candidate writes and compiles the code for a coding Question, the test cases you have defined will be validated against the Candidate's code to show the execution status and results. Based on whether all your Test cases execute successfully and return the expected output from the Candidate's code, the score will be calculated for the Question.
For coding Questions, you can define the test cases that must be validated against the Candidate's code. In the Question, you can define test cases of two categories: Sample Test Cases and Hidden Test Cases.
Refer to the Coding Question Test Cases topic to understand the different Test case types you can add to your Questions.
Creating a new test case
1. While creating a new Coding question, or while editing an existing one, click the "Add test case" button on the "Test Cases" step.
2. In the Add Test Case window, define the test case's name, difficulty, score, the input values, and the expected output values.
- To avoid EOF issues, we recommend all test cases that require a multi-value input to define the input in the format suggested below:
|number of lines (ex. 4)
value of line 1 (ex. 100)
value of line 2 (ex. 500)
value of line 3 (ex. 40)
value of line 4 (ex. 200)
- Furthermore, you can leverage our code stub generator to manage the input parsing for candidates. The test case input format for our code stubs are the following:
|5 separate input parameters e.g. foobar(a, b, c, d, e) - separate parameters by newline:
|Int / String Array - the size of the array followed by the list of values in the array
- Select the "Mark as a sample test case" only if you want to identify a test case as a sample type. You can add the required number of sample test cases to a question and choose not to assign scores for them.
- Click Save to add the Test case.
- In a similar manner, you can add the required number of hidden test cases to the Question. Hidden test cases should contain edge scenarios to validate the Candidates' code solution to this Question. When the Candidate compiles the code, the hidden test cases will be executed to show the status and helps the Candidate to know if the code returns the expected results.
The following image illustrates the Candidate's view of test case execution status for the compiled code in the Test. Note that, the Candidate can view the input and expected output values only for the Sample test case. For the hidden test cases, only the test execution results are displayed.