How to Write a Unit Test Problem on CodeHS
Writing a unit test problem with CodeHS Create makes it really easy for you to create custom problems for your students and give them instant feedback.
Unit test problems allow you to easily test a function or method written by a student by just writing the solution and picking some test calls.
Step 1: Select a Unit Test in your desired programming language
First select Unit Test and the language you want the function or method to be in. Then click Create Activity.
Step 2: Write the description students will see when they visit the problem
This will pop up as a description of the goal of the problem. You can write in the text in Markdown as well and see a preview.
Step 3: Write the starter code and solution code for the method
Here you need to write the method or function. At the top we wrote the empty method, then under solution code we write the solution for this method. Student’s can solve it in any way as long as they get the right outputs.
Step 4: Write the test cases
Once you write your solution, we automatically detect the method name and signature. Then you can go and write as many test cases as you want.
Step 5: Students Receive Instant Feedback on Your Problem
That’s it! Now when students are solving this problem they’ll get immediate feedback on how they performed on the test cases!
As more teachers create problems, these will build up a shared repository of great coding challenges in the Problem Bank that you’ll be able to use in your class as well!
You can also watch this 2 minute screencast on how to create a problem.
Questions? Email hello@codehs.com!