Discover how CodeGrade's Custom Test block lets you write your own grading logic in any language. Perfect for partial credit, complex logic, or specialized tools.
Guides
April 23, 2025

How to use custom test blocks

In 30 seconds...

Want full control over autograding? CodeGrade’s Custom Test block lets you script your own grading logic using Bash, Python, or any language you choose. Whether you're awarding partial credit, integrating external tools, or evaluating complex outputs, this feature adapts to your needs.

The Custom Test block is one of the most flexible tools in CodeGrade’s AutoTest system. It lets you write your own grading script in any language (like Bash or Python), so you’re not limited to predefined test types like input/output checks or basic unit tests.

Your script can perform any evaluation logic you need, and then output a JSON object to communicate the results back to CodeGrade. For example:

{ "tag": "points", "points": "3/5" } 

That line means the student earned 3 out of 5 points—and that’s all CodeGrade needs to assign a grade.

This combination of scripting freedom and simple output formatting makes Custom Tests a great fit for assignments that require a little extra complexity.

Why Use a Custom Test Block

There are several situations where the standard AutoTest blocks just don’t cut it. Here’s when a Custom Test block really shines:

  1. Complex or Multi-Step Evaluations

Maybe the assignment requires generating a file, checking its contents, validating a format, and then scoring based on that. A Custom Test lets you script all those steps in one place.

This is perfect for tasks that go beyond a single input/output comparison or can’t be fully captured by a unit test framework.

  1. Custom Grading Logic

Want to award partial credit? Or maybe you have your own scoring rules based on specific criteria?

With a Custom Test, you can write the exact logic you need. For example, you can check whether each part of the output meets expectations and assign points incrementally, rather than using all-or-nothing scoring.

  1. External or Specialized Tools

If your assignment involves custom tools, external libraries, or even a specific linter or data analysis framework, no problem.

You can run those tools inside your script. Since the Custom Test doesn’t rely on built-in test runners, it gives you full control.

  1. When Other Blocks Don’t Fit

Sometimes, an assignment just doesn’t fit any of the built-in templates. That’s where Custom Test becomes your go-to.

In short: if you can script it, you can grade it.

Get your assignment automatically graded today.

Example Assignments and Setups

To show how Custom Tests work in practice, here are two real-world-style examples using Python and C++ assignments.

Example 1: Data Validation with Partial Scoring

Assignment: Students write a Python program that outputs a JSON object with specific fields—say, "name", "age", and "email". You want to check that the structure is correct and the values are valid, but also give partial credit if only part of the output is right.

Custom Test Setup: The script runs the student’s code and captures the output. Then, it parses the JSON (using something like Python’s json library), checks for the required keys, and verifies the values.

Maybe the structure is perfect, but the value of "age" isn’t an integer. No problem—the script can assign partial credit.

{"tag": "points", "points": "1/2"}

This result gets passed back to CodeGrade, and the student earns 1 out of 2 points for that test. 

Example 2: C++ Array Processing with Custom Grading Logic

Assignment: Students write a C++ function process_numbers() that works with an array of integers. It should return:

  • The sum of positive numbers
  • The count of negative numbers
  • The average of all numbers

You want to grade based on how many of these values are correct.

Custom Test Setup: The grading script compiles and runs the student’s program, captures the output, and checks the values.

If everything is correct—great! Full points.

But if only one or two values are right, the script awards partial credit based on what was correct. For example:

{"tag": "points", "points": "2/3"} 

Again, this simple JSON output is all CodeGrade needs to update the grade.

Connecting to the Rubric

Each Custom Test block connects to a rubric category using the Connect Rubric step in AutoTest. The "points": "X/Y" value from your script maps directly to the rubric.

You can choose whether students see just the final score or also the script output and feedback—it’s up to you.

How Students Benefit

Custom Tests don’t just make things easier for instructors—they help students too.

  • Partial credit means fairer grading
    Students get recognized for what they did right. Instead of a zero for an “almost correct” submission, they might earn 1/2 or 8/10 points. That feels more just and motivating.

  • Supports complex, real-world tasks
    You can give students more open-ended or realistic assignments (like building a small app or machine learning model) and still autograde them. That keeps your curriculum closer to industry practices.

  • Immediate feedback on advanced assignments
    Even for complex projects, students get instant results. If a model’s accuracy is low or an output format is off, the Custom Test can show that immediately—no need to wait for manual grading.

  • Encourages creativity and deeper learning
    Because your script can recognize multiple correct approaches, students don’t have to guess the one “right” way to pass the test. They’re free to think creatively and solve problems in their own style.

In conclusion

The Custom Test block is a key feature of CodeGrade’s AutoTest system. It unlocks a wide range of grading possibilities, particularly for creative, complex, or open-ended assignments.

If you’ve ever thought, “I wish I could grade this automatically, but it’s too nuanced,” the Custom Test block is likely the solution you need.

Need assistance with writing your first Custom Test? Feel free to reach out to our Support team.

Let your grading match your assignments—flexible, fair, and focused on learning.

Continue reading

Jupyter Notebooks Improvements + Release Schedule!

Learn how to automatically grade Jupyter Notebook with our new integration. Watch our latest webinar to see it in action!

Simple Python Test vs. Pytest: Which One to Use?

Choosing between Simple Python Test and Pytest for CodeGrade assignments

Watch now! How to Teach Prompt Engineering

AI Engineering Lab Webinar on AI-Assisted Coding in Introductory Courses

How to set up a Data Structures course with Delaware State

Explore Delaware State University's innovative Java course, where freshmen master object-oriented programming, algorithm design, and clean coding practices to launch their tech careers.

Sign up to our newsletter

Transform your coding course today!