KKeine Bearbeitungszusammenfassung Markierung: Manuelle Zurücksetzung |
KKeine Bearbeitungszusammenfassung |
||
Zeile 16: | Zeile 16: | ||
==B: Issues with the setup== | ==B: Issues with the setup== | ||
Assuming your folder structure looks like the image to the right, where your code is under <code>src</code> and <code>test</code> is your folder for tests: | Assuming your folder structure looks like the image to the right, where your code is under <code>src</code> and <code>test</code> is your folder for tests: | ||
[[Datei:Folderstructure-intellij.png| | [[Datei:Folderstructure-intellij.png|thumb|Folder Structure Example]] | ||
===1. Test Sources Root=== | ===1. Test Sources Root=== | ||
* Right-click on <code>test</code>, <code>Mark as</code>, <code>Test Sources Root</code>. | * Right-click on <code>test</code>, <code>Mark as</code>, <code>Test Sources Root</code>. | ||
[[Datei:Mark as Test Sources Root.png| | [[Datei:Mark as Test Sources Root.png|thumb|Mark Folder as Test Sources Root]] | ||
===2. build.gradle=== | ===2. build.gradle=== | ||
Zeile 51: | Zeile 51: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Datei:Build.gradle.png| | [[Datei:Build.gradle.png|thumb|How <code>build.gradle</code> is supposed to look]] | ||
===3. Project Structure=== | ===3. Project Structure=== | ||
# Navigate to <code>File</code>, <code>Project Structure</code>. | # Navigate to <code>File</code>, <code>Project Structure</code>. | ||
[[Datei:Nav to project structure.png| | [[Datei:Nav to project structure.png|thumb|Navigate to <code>Project Structure</code>]] | ||
# Under <code>Modules</code>, check that it looks like the following image: | # Under <code>Modules</code>, check that it looks like the following image: | ||
[[Datei:Modules.png| | [[Datei:Modules.png|thumb|How <code>Modules</code> should look]] | ||
If you have a <code>test</code> folder on the same level as <code>W0XH0Y</code>, delete it by selecting it, then clicking the minus button (see the orange marking). | If you have a <code>test</code> folder on the same level as <code>W0XH0Y</code>, delete it by selecting it, then clicking the minus button (see the orange marking). | ||
===4. Build options=== | ===4. Build options=== | ||
# Navigate to <code>File</code>, <code>Settings</code>. | # Navigate to <code>File</code>, <code>Settings</code>. | ||
[[Datei:Nav to settings.png| | [[Datei:Nav to settings.png|thumb|Navigate to <code>Settings</code>]] | ||
# Expand (using the small arrows <code>></code>) to the following level: <code>Build, Execution, Deployment<nowiki></code> ''(1)'', <code>Build Tools</code> ''(2)''. Click <code>Gradle</code> ''(3)''. | # Expand (using the small arrows <code>></code>) to the following level: <code>Build, Execution, Deployment<nowiki></code> ''(1)'', <code>Build Tools</code> ''(2)''. Click <code>Gradle</code> ''(3)''. | ||
# Under <code>Run tests using:</code> ''(4)'', select <code>IntelliJ IDEA</code> ''(5)'', if <code>Gradle</code> is selected. | # Under <code>Run tests using:</code> ''(4)'', select <code>IntelliJ IDEA</code> ''(5)'', if <code>Gradle</code> is selected. | ||
# Click <code>OK</code>. | # Click <code>OK</code>. | ||
[[Datei:Build Gradle Use IntelliJ.png| | [[Datei:Build Gradle Use IntelliJ.png|thumb|Setting Gradle's Test Runner to IntelliJ]] | ||
==C: Still not working?== | ==C: Still not working?== | ||
In case your tests still don't work, open a Zulip thread. | In case your tests still don't work, open a Zulip thread. |
Version vom 28. November 2022, 09:43 Uhr
This quick guide shall help you fix the most common JUnit errors.
It has been written for IntelliJ - might work similarly with other IDEs, but might also not.
In case your tests still don't work after going through these steps (please try to run your tests after each section and see if the issue has been resolved), open a Zulip thread.
A: Issues within the Test classes
General things to check:
- Does the package name at the top of each test class correspond to the actual folder structure?
- If a class says
package pg.dp;
for example, but is sitting in the folderpg
, remove the.dp
. If it sayspackage pg;
instead, but is sitting inpg/dp
, try adding.dp
to thepackage
.
- Is the test trying to import libraries you need to add first?
- Check the
import
section and hover over red import statements. You should get a suggestion to import the corresponding library. Click it.
- Are the tests relying on classes you don't have in your
src/pgdp.taskname
folder? Or on classes in thetestfoldername
folder?
- Check if you have overlooked a class you need to implement per the import statement, or if the test was maybe written for another implementation than the one you chose. If you're trying to run student tests from the Github repo, check the corresponding pull request and see if you maybe forgot to add the missing class to your test folder. Don't shy away from asking the author if their test is correct, either.
- Is there a semicolon, bracket, etc missing?
B: Issues with the setup
Assuming your folder structure looks like the image to the right, where your code is under src
and test
is your folder for tests:
1. Test Sources Root
- Right-click on
test
,Mark as
,Test Sources Root
.
2. build.gradle
Open build.gradle
.
- Does the file contain the name of the test folder (here:
test
) in single brackets undersourceSets, test, java
in the arraysrcDirs
? (1)
- If not, copy the following at the proper location (see image):
test {
java {
srcDirs = ['test']
}
}
- Does it contain the JUnit dependency? (2)
- If not, copy the following at the proper location (see image). You may need to change the version number according to the JUnit version you have added.
dependencies {
implementation 'org.junit.jupiter:junit-jupiter:5.8.1'
}
- Does it specify
useJUnitPlatform()
? (3)
- If not, copy the following at the proper location (see image):
test{
useJUnitPlatform()
}
3. Project Structure
- Navigate to
File
,Project Structure
.
- Under
Modules
, check that it looks like the following image:
If you have a test
folder on the same level as W0XH0Y
, delete it by selecting it, then clicking the minus button (see the orange marking).
4. Build options
- Navigate to
File
,Settings
.
- Expand (using the small arrows
>
) to the following level:Build, Execution, Deployment<nowiki>
(1),Build Tools
(2). ClickGradle
(3). - Under
Run tests using:
(4), selectIntelliJ IDEA
(5), ifGradle
is selected. - Click
OK
.
C: Still not working?
In case your tests still don't work, open a Zulip thread.