Last active
July 4, 2020 19:01
-
-
Save pazz/f109183b56cf8919e1efd358f3b7cc9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import check50 | |
import check50java | |
REPORT = {'testcases': [ | |
{'name': 'getPriceFails', | |
'classname': 'ItemTest', | |
'time': '0.035', | |
'pass': False, | |
'message': 'Item has no constructor for argument java.lang.String, int, int'}, | |
{'name': 'testToString', | |
'classname': 'ItemTest', | |
'time': '0.001', | |
'pass': False, | |
'message': 'Item has no constructor for argument java.lang.String, int, int'}, | |
{'name': 'pricePerUnitWeight', | |
'classname': 'ItemTest', | |
'time': '0.001', | |
'pass': False, | |
'message': 'Item has no constructor for argument java.lang.String, int, int'}, | |
{'name': 'getDescription', | |
'classname': 'ItemTest', | |
'time': '0.001', | |
'pass': False, | |
'message': 'Item has no constructor for argument java.lang.String, int, int'}, | |
{'name': 'getPrice', | |
'classname': 'ItemTest', | |
'time': '0.002', | |
'pass': False, | |
'message': 'Item has no constructor for argument java.lang.String, int, int'} | |
], | |
'failures': 0, | |
'tests': 5, | |
'passed': 5 | |
} | |
@check50.check() | |
def item_exists(): | |
"""Item.java exists.""" | |
check50.exists("Item.java") | |
@check50.check(item_exists) | |
def item_compiles(): | |
"""Item.java compiles.""" | |
check50java.compile("Item.java") | |
@check50.check(item_exists) | |
def run_tests(): | |
"""ItemTest""" | |
# check50.include('tests/ItemTest.class') | |
#report = check50java.junit5.run_test('ItemTest') | |
# check50._api.log(str(report)) | |
return REPORT | |
def create_check(testclass, i): | |
def check(rep): | |
check50._api.log(str(len(rep['testcases']))) | |
check50._api.log(str(i)) | |
return rep | |
check.__name__ = f"{i}" | |
check.__doc__ = f"{check_id} passes" | |
return check | |
# Copy compiled test class into student's submission | |
check50.include('tests/ItemTest.class') | |
testclass = "itemTest" | |
# run junit once to generate report and extract test cases | |
# report = check50java.junit5.run_test(testclass) | |
report = REPORT # for now | |
i = 0 | |
for case in report['testcases']: | |
testmethod = case['name'] | |
check_id = f"{testclass}__{testmethod}" | |
check = create_check(testclass, i) | |
i += 1 | |
# Register the check with check50 | |
check = check50.check(run_tests)(check) | |
# Add the check to global module scope | |
globals()[check_id] = check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full output: