All Collections
Tests / Autograding
Writing tests
Creating tests for the codePost autograder
Creating tests for the codePost autograder

Learn how to define tests that can be run from within codePost.

James avatar
Written by James
Updated over a week ago

Creating Tests

Creating Tests with the codePost autograder involves two steps:

  • Creating an environment

  • Writing tests 

Creating an environment

Environment = The set of specifications used to create the container in which your tests will run. An environment includes the following properties:

  • A language (Which languages does the codePost autograder support?)

  • Package dependencies = external packages you want to make available to student code or your tests

  • Run script = a code snippet that runs each time you run tests against a student's code. For compiled languages, the run script includes compilation commands.

  • Helper files = files you want to make available to student code or your tests

  • Solution code = code you consider correct, which you can use to make sure your tests are functioning properly

An environment is never exposed to students. 

If you want to learn more about creating an environment, check out our article here

Writing tests

These are the tests that you will run against student code! There are two ways to define tests from within codePost.

The Test Editor

The Test Editor is ideal for users:

  • Who are starting test-writing from scratch (don't have any pre-written tests to port to codePost)

  • Who want to quickly write simple tests

The Test Editor allows you create the following types of tests.

  • Input / Output tests: Specify a command, input, and the expected output. This test will pass only if the student's code produces output that matches the expected output. 

  • Unit tests: (Java and Python only) Write a code snippet to specify the test in your language of choice, and report the results of the test back to codePost from within your snippet.

  • Shell Test: Write a bash script that specifies your test and report the results back to codePost.

File Mode is a more flexible and advanced method of writing tests. When you enter File Mode you'll be able to work with the exact files which are run on codePost servers when a test is executed.

File Mode is useful for users who:

  • Have already written test scripts and are porting those to codePost

  • Want to dump test logs to a file (visible to students from within the code console)

  • Are writing tests which depend on other tests

  • Want to work with precisely the files that codePost will run in your environment

To define a test from the File Mode, all you need to do is use codePost's test reporting syntax from within any file you create. 

Did this answer your question?