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.
You can define the test cases that must be validated against the candidate's code for coding questions. 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.
Note: Please refer to Test Cases in your Coding Question to understand the usage of Test cases while creating coding questions for HackerRank Tests.
Creating a New Test Case
1. While creating a new Coding question or editing an existing one, click on 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, 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 on the Save button to add the Test case.
- Similarly, 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 help 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 only view the input and expected output values for the Sample test case. For the hidden test cases, only the test execution results are displayed.