Skip to main content

A check50 extension for running and interpreting junit5 unit tests

Project description

check50_junit

This is an extension for the CS50 automarker check50 for compiling and running Junit5 unit tests and raising the resulting failures directly as check50 Failures to be used in checks.

This module ships with Junit5's stand-alone console launcher.

Your problem set only needs to include the compiled bytecode of junit test classes, which are compiled against your model solution to the exercise. This gets around the issue that unit tests may not compile for student's code due to unexpected method signatures class identifiers. Such errors will be reflected in the JUnit's report XML file.

Example Usage

TLDR: import check50_junit; add your compiled junit test classes to your pset, and use check50_junit5.run_and_interpret_test within your checks. A full example follows.

All examples below assume that you're importing check50 and check50_junit.

  1. Write your model solution and unit test classes and manually compile them.

    public class Drink {
        private final int volume;
    
        public Drink(int v) {
            volume = v;
        }
    
        int getVolume() {
            return volume;
        }
    
    import static org.junit.jupiter.api.Assertions.*;
    import org.junit.jupiter.api.Test;
    
    class DrinkTest {
      @Test
      public void getVolume() {
        Drink d = new Drink(200);
        assertEquals(200, d.getVolume());
      }
    }
    
  2. Move the bytecode DrinkTest.class somewhere into your pset directory, say under tests/.

  3. Add a check as follows (I would usually have this depend on class exists, compiles, and can be instantiated checks).

    @check50.check()
    def drink_getVolume():
        """Test Drink.getVolume()"""
        check50_junit.run_and_interpret_test(
            classpaths=['tests/'],
            args=['--select-method', 'DrinkTest#getVolume'])
    

    This will run the precompiled unit test on the student submission, parse junit's XML report and raise any check50.Failures as appropriate for the result. In this case it would raise a check50.Mismatch exception if the assertEquals within the unit test is thrown.

  4. Make sure to add check50-java as a dependency in your pset's .cs50.yml:

    check50:
      dependencies:
        - check50-java
      files:
        - !exclude "*"
        - !include "*.java"
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

check50_junit-0.2.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

check50_junit-0.2-py3-none-any.whl (2.0 MB view details)

Uploaded Python 3

File details

Details for the file check50_junit-0.2.tar.gz.

File metadata

  • Download URL: check50_junit-0.2.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for check50_junit-0.2.tar.gz
Algorithm Hash digest
SHA256 168d8ce527f2b133f53413b2d266372ddb44c59840a78fbb64dd520baeecf631
MD5 50b880fb703723ea6d08ed047204a15a
BLAKE2b-256 6cf88cbeff949c8f834ac5be6059382cbb0f153c0a804a2612853169a2453e72

See more details on using hashes here.

Provenance

File details

Details for the file check50_junit-0.2-py3-none-any.whl.

File metadata

  • Download URL: check50_junit-0.2-py3-none-any.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for check50_junit-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f6bd72d90cb7fd612346b601088c871d2fcbf2d006a63f986297c206265f96bd
MD5 b36453fa05c47a8c06f254883d17b8a3
BLAKE2b-256 9d2bb8609b1c20789e17aeb4e97f5eac7753fd19e548275ac39fe2fc5baa209a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page