Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Need an example for multiple tests adding up to 100 #56

Open
shaharyi opened this issue Jul 27, 2022 · 3 comments
Open

Need an example for multiple tests adding up to 100 #56

shaharyi opened this issue Jul 27, 2022 · 3 comments

Comments

@shaharyi
Copy link

Hi,
I work with Java and Gradle. I followed the example repository .
I tried it myself, but the Action runs all 3 tests as a single test, 3 times.
So one broken test causes 0 points total.

Can you give an example that works? maybe improve on the example repository.

My assignment:
https://classroom.github.com/classrooms/83712254/assignments/olympics

@shaharyi
Copy link
Author

An update:
I found in Gradle CLI docs that you can specify the test classes:
gradle test --tests MyTestClass
But If there is a compilation problem in ANY of the tests, the score is zero.
Only if all tests compile, each of them get their respective points.
Is there a way to easily fix this, perhaps in Gradle or Actions config?

@stevenbitner
Copy link

I'm no Gradle expert, but I had a similar issue in the past and used the sourceSets attribute to exclude all classes that were not required for a given test. For example:

task test_constructor (type: Test) {
	filter.includeTestsMatching "ConstructorTest"
}

// other test tasks here
// ....

sourceSets {
    if (project.gradle.startParameter.taskNames.contains("test_constructor")) {
        test.java.exclude '**/LotsOfGuessesTest*'
        test.java.exclude '**/TestMain*'
        test.java.exclude '**/TestMainLoop*'
        sourceSets.main.java.excludes = ['Main*']
    }
    else if (project.gradle.startParameter.taskNames.contains("test_loser")) {
        test.java.exclude '**/TestMain*'
        test.java.exclude '**/TestMainLoop*'
        sourceSets.main.java.excludes = ['Main*']
    }
    else if (project.gradle.startParameter.taskNames.contains("test_lots_of_guesses")) {
        test.java.exclude '**/TestMain*'
        test.java.exclude '**/TestMainLoop*'
        sourceSets.main.java.excludes = ['Main*']
    }
    else if (project.gradle.startParameter.taskNames.contains("test_main")) {
        test.java.exclude '**/TestMainLoop*'
    }
}

Then, in my autograding.json file I call the tests one by one. To call the "constructor" test from the Gradle snippet above for instance, the test is:

{
  "name": "Test constructors",
  "setup": "",
  "run": "timeout 60 gradle test_constructor",
  "input": "",
  "output": "",
  "comparison": "included",
  "timeout": 1,
  "points": 20
}

I hope this helps.

@shaharyi
Copy link
Author

shaharyi commented Nov 10, 2022 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants