Skip to content
Snippets Groups Projects
Commit 5ef835e4 authored by PIERRON Laurent's avatar PIERRON Laurent :man_in_tuxedo_tone1:
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
target
.DS_Store
.vscode
## Objectif
Ce TP est destiné à vérifier le fonctionnement de la chaîne automatique de compilation et d'exécution d'un programme Java :
- compilation (javac)
- tests unitaires (junit)
- test de couverture (jacoco)
La mise en oeuvre est effectuée par l'outil de construction de projet Maven.
## Préambule
Vérifier que le programme Maven est installé :
```
$ mvn -version
Maven home: /usr/local/Cellar/maven/3.8.7/libexec
Java version: 19.0.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/19.0.1/libexec/openjdk.jdk/Contents/Home
Default locale: fr_FR, platform encoding: UTF-8
OS name: "mac os x", version: "12.6.2", arch: "x86_64", family: "mac"
````
Si vous utilisez l'IDE VS Code vous pouvez installer les extensions suivantes :
- Java Extension Pack : https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack
- Coverage Gutters : https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
- SonarLint : https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarlint-vscode
## Création de votre branche de travail
Clonez le projet sur votre ordinateur : `git clone https://gitlab.univ-lorraine.fr/pierron9/sphere`
Créez une branche pour travailler. Choisissez comme nom de branche votre nom de login sur `https://gitlab.univ-lorraine.fr/`
```
cd sphere
git branch <your branch name>
git switch <your branch name>
```
Testez que vous êtes au bon endroit : `git status`
Créez la branche sur le dépôt distant : `git push --set-upstream origin <your branch name>`
Vous devriez avoir cela dans le répertoire `sphere` :
````
sphere
├── README.md
├── pom.xml
└── src
├── main
│ └── java
│ └── fr
│ └── nancy
│ └── iut
│ └── Sphere.java
└── test
└── java
└── fr
└── nancy
└── iut
└── SphereTest.java
````
## Passage des tests
Passez le test, avec la commande `mvn test` ou de puis votre IDE.
Corrigez le programme pour que le test passe.
Enregistrez votre travail et synchronisez le sur le dépôt.
## Couverture de code
Vérifiez la couverture de code : `mvn jacoco:prepare-agent install jacoco:report`
Puis visualisez le résultat : `open target/site/jacoco/index.html`
Vous pouvez aussi voir le résultat dans l'IDE grâce à `Covergae Gutters`, les marques vertes indiquent des lignes analysées, les marques rouges, les lignes non testées.
## Travail supplémentaire
Ajoutez des tests pour arriver à 100% de couverture de code. Vous pouvez avoir besoin de la documentation de JUnit : https://junit.org/junit5/docs/5.7.2/user-guide/index.html
La bonne méthode est d'ajouter un test à la fois, de le faire passer puis `committer` pour valider le travail.
Une fois la couverture à 100% obtenue, synchronisez votre travail avec le dépôt.
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.nancy.iut</groupId>
<artifactId>TPTestIUTJava</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>TPTestIUTJava</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>java3d</groupId>
<artifactId>vecmath</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package fr.nancy.iut;
import javax.vecmath.Point3d;
/**
* Created by dparsons on 12/08/15.
*/
public class Sphere {
// ***********************************************************************
// Constructors
// ***********************************************************************
public Sphere() {
radius_ = 0.0;
pos_ = new Point3d();
}
public Sphere(double radius) {
radius_ = radius;
pos_ = new Point3d();
}
public Sphere(double radius, Point3d pos) {
radius_ = radius;
pos_ = pos;
}
// ***********************************************************************
// Methods
// ***********************************************************************
public double computeVolume() {
return 4 * Math.PI * Math.pow(radius_, 2) / 3;
}
public double distanceTo(Sphere other) {
return pos_.distance(other.pos_);
}
public double distanceSquaredTo(Sphere other) {
return pos_.distanceSquared(other.pos_);
}
public boolean inContactWith(Sphere other) {
return distanceSquaredTo(other) <= Math.pow(radius_ + other.radius_, 2);
}
// ***********************************************************************
// Accessors
// ***********************************************************************
public Point3d getPos() {
return pos_;
}
public double getRadius() {
return radius_;
}
// ***********************************************************************
// Attributes
// ***********************************************************************
protected double radius_ = 0.0;
protected Point3d pos_;
}
package fr.nancy.iut;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import javax.vecmath.Point3d;
/**
* Created by dparsons on 12/08/15.
*/
public class SphereTest {
@Test
public void testComputeVolume() throws Exception {
Sphere mySphere = new Sphere(1.5);
assertEquals(14.137166941154069, mySphere.computeVolume(), 0.0);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment