Guide:Help, my tests arent running: Unterschied zwischen den Versionen

Aus TUTI
KKeine Bearbeitungszusammenfassung
(updated to wikitext syntax)
Zeile 4: Zeile 4:


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.
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==
==A: Issues within the Test classes==
General things to check:
General things to check:
# Does the package name at the top of each test class correspond to the actual folder structure?
# Does the package name at the top of each test class correspond to the actual folder structure?
 
* If a class says <code>package pg.dp;</code> for example, but is sitting in the folder <code>pg</code>, remove the <code>dp</code>. If it says <code>package pg</code> instead, but is sitting in <code>pg/dp</code>, try adding <code>.dp</code> to the <code>package</code>.
* If a class says `package pg.dp;` for example, but is sitting in the folder `pg`, remove the `dp`. If it says `package pg` instead, but is sitting in `pg/dp`, try adding `.dp` to the `package`.
# Is the test trying to import libraries you need to add first?
 
* Check the <code>import</code> section and hover over red import statements. You should get a suggestion to import the corresponding library. Click it.
2. Is the test trying to import libraries you need to add first?
# Are the tests relying on classes you don't have in your <code>src/pgdp.taskname</code> folder? Or on classes in the <code>testfoldername</code> folder?
  - Check the `import` section and hover over red import statements. You should get a suggestion to import the corresponding library. Click it.
* 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](https://github.com/MaximilianAnzinger/pgdp2223-tests), 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.
3. Are the tests relying on classes you don't have in your `src/pgdp.taskname` folder? Or on classes in the `testfoldername` folder?
# Is there a semicolon, bracket, etc missing?
  - 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](https://github.com/MaximilianAnzinger/pgdp2223-tests), 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.
4. Is there a semicolon, bracket, etc missing?




==B: Issues with the setup==
==B: Issues with the setup==
 
Assuming your folder structure looks like this, where your code is under <code>src</code> and <code>test</code> is your folder for tests:
Assuming your folder structure looks like this, where your code is under `src` and `test` is your folder for tests:
[[Datei:Folderstructure-intellij.png|mini]]
 
![image-20221127174409662](C:\Users\Jacob\AppData\Roaming\Typora\typora-user-images\image-20221127174409662.png)


===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 `test`, `Mark as`, `Test Sources Root`
[[Datei:Mark as Test Sources Root.png|mini]]
 
  ![Screenshot (4)](C:\Users\Jacob\Pictures\Screenshots\Screenshot (4).png)


===2. build.gradle===
===2. build.gradle===
Open <code>build.gradle</code>.
# Does the file contain the name of the test folder (here: <code>test</code>) in single brackets under <code>sourceSets, test, java</code> in the array <code>srcDirs</code>? ''(1)''


Open `build.gradle`.
* If not, copy the following at the proper location (see image):
 
<syntaxhightlighting lang="java">
1. Does the file contain the name of the test folder (here: `test`) in single brackets under `sourceSets, test, java` in the array `srcDirs`? _(1)_
test {
 
    java {
  - If not, copy the following at the proper location (see image):
        srcDirs = ['test']
 
    }
    ```java
}
    test {
</syntaxhighlighting>
            java {
# Does it contain the JUnit dependency? ''(2)''
                srcDirs = ['test']
* 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.
            }
<syntaxhightlighting lang="java">
        }
dependencies {
    ```
    implementation 'org.junit.jupiter:junit-jupiter:5.8.1'
 
}
2. Does it contain the JUnit dependency? _(2)_
</syntaxhighlighting>
 
  - 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.
 
    ```java
    dependencies {
        implementation 'org.junit.jupiter:junit-jupiter:5.8.1'
    }
    ```
 
3. Does it specify `useJUnitPlatform()`? _(3)_
 
  - If not, copy the following at the proper location (see image):
 
    ```java
    test{
        useJUnitPlatform()
    }
    ```


![image-20221127175416357](C:\Users\Jacob\AppData\Roaming\Typora\typora-user-images\image-20221127175416357.png)
# Does it specify <code>useJUnitPlatform()</code>? ''(3)''
* If not, copy the following at the proper location (see image):
<syntaxhightlighting lang="java">
test{
    useJUnitPlatform()
}
</syntaxhighlighting>
[[Datei:Build.gradle.png|mini]]


===3. Project Structure===
===3. Project Structure===
 
# Navigate to <code>File</code>, <code>Project Structure</code>.
1. Navigate to `File`, `Project Structure`.
[[Datei:Nav to project structure.png|mini]]
 
# Under <code>Modules</code>, check that it looks like the following image:
  ![Screenshot (5)](assets/Screenshot (5).png)
[[Datei:Modules.png|mini]]
 
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).
2. Under `Modules`, check that it looks like the following image:
 
  ![image-20221127180638291](assets/image-20221127180638291.png)
 
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===
===4. Build options===
 
# Navigate to <code>File</code>, <code>Settings</code>.
1. Navigate to `File`, `Settings`.
[[Datei:Nav to settings.png|mini]]
 
# Expand (using the small arrows <code>></code>) to the following level: <code>Build, Execution, Deployment<c/code> ''(1)'', <code>Build Tools</code> ''(2)''. Click <code>Gradle</code> ''(3)''.
  ![Screenshot (6)](assets/Screenshot (6).png)
# Under <code>Run tests using:</code> ''(4)'', select <code>IntelliJ IDEA</code> ''(5)'', if <code>Gradle</code> is selected.
 
# Click <code>OK</code>.
2. Expand (using the small arrows `>`) to the following level: `Build, Execution, Deployment` _(1)_, `Build Tools` _(2)_. Click `Gradle` _(3)_.
[[Datei:Build Gradle Use IntelliJ.png|mini]]
 
3. Under `Run tests using:` _(4)_, select `IntelliJ IDEA` _(5)_, if `Gradle` is selected.
 
4. Click `OK`.
 
![Screenshot (7)](assets/Screenshot (7).png)


==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 27. November 2022, 21:20 Uhr

This quick guide shall help you fix the most common JUnit errors.

It has been written for IntelliJ - might also 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:

  1. 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 folder pg, remove the dp. If it says package pg instead, but is sitting in pg/dp, try adding .dp to the package.
  1. 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.
  1. Are the tests relying on classes you don't have in your src/pgdp.taskname folder? Or on classes in the testfoldername 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](https://github.com/MaximilianAnzinger/pgdp2223-tests), 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.
  1. Is there a semicolon, bracket, etc missing?


B: Issues with the setup

Assuming your folder structure looks like this, where your code is under src and test is your folder for tests:

Folderstructure-intellij.png

1. Test Sources Root

  • Right-click on test, Mark as, Test Sources Root.
Mark as Test Sources Root.png

2. build.gradle

Open build.gradle.

  1. Does the file contain the name of the test folder (here: test) in single brackets under sourceSets, test, java in the array srcDirs? (1)
  • If not, copy the following at the proper location (see image):

<syntaxhightlighting lang="java"> test {

   java {
       srcDirs = ['test']
   }

} </syntaxhighlighting>

  1. 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.

<syntaxhightlighting lang="java"> dependencies {

   implementation 'org.junit.jupiter:junit-jupiter:5.8.1'

} </syntaxhighlighting>

  1. Does it specify useJUnitPlatform()? (3)
  • If not, copy the following at the proper location (see image):

<syntaxhightlighting lang="java"> test{

   useJUnitPlatform()

} </syntaxhighlighting>

Build.gradle.png

3. Project Structure

  1. Navigate to File, Project Structure.
Nav to project structure.png
  1. Under Modules, check that it looks like the following image:
Modules.png

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

  1. Navigate to File, Settings.
Nav to settings.png
  1. Expand (using the small arrows >) to the following level: Build, Execution, Deployment<c/code> (1), Build Tools (2). Click Gradle (3).
  2. Under Run tests using: (4), select IntelliJ IDEA (5), if Gradle is selected.
  3. Click OK.
Build Gradle Use IntelliJ.png

C: Still not working?

In case your tests still don't work, open a Zulip thread.