0% found this document useful (0 votes)
40 views7 pages

Travail Pratique nr.3: Tidpp

1) The document describes a practical work assignment on unit testing, dependency injection, and mockups for a computer science student in Moldova. 2) The assignment involves testing different cases for validating triangles using the JUnit testing framework in Java, including checking for null/negative sides, incorrect side lengths, and identifying isosceles, scalene, and equilateral triangles. 3) The conclusion states that the goal was to learn about testing and deployment in the development cycle using Java tools like JUnit, to study black box testing, and to become familiar with dependency injection. The testing step is important to avoid costly risks down the line.

Uploaded by

saptesate31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views7 pages

Travail Pratique nr.3: Tidpp

1) The document describes a practical work assignment on unit testing, dependency injection, and mockups for a computer science student in Moldova. 2) The assignment involves testing different cases for validating triangles using the JUnit testing framework in Java, including checking for null/negative sides, incorrect side lengths, and identifying isosceles, scalene, and equilateral triangles. 3) The conclusion states that the goal was to learn about testing and deployment in the development cycle using Java tools like JUnit, to study black box testing, and to become familiar with dependency injection. The testing step is important to avoid costly risks down the line.

Uploaded by

saptesate31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Ministère de l'éducation, de la culture et de la recherche

de la République de Moldova
Université technique de Moldavie
Faculté d’Ordinateur, Informatique et Microélectronique
Filière francophone “Informatique”

TIDPP

Travail pratique nr.3


Thème: Unit testing, Dependency Injection, Mockups

Effectué par l’étudiant de gr FI-191 : nnn

Vérifié par le professeur : Rusu Viorel

Chișinau 2020
But: passer les étapes de test et de déploiement dans le cycle de
développement d'un programme et en utilisant les outils Java
spécifiques à ces étapes.
1)
a)

b)

c)
2)
3) import junit.framework.TestCase;
import org.junit.Test;

public class TriangleTest extends TestCase {

public void testIsSideNull() throws InvalidTriangleException{


try {
Triangle t1 = new Triangle(0,2,3);
fail("InvalidTriangleException because side [var1] of triangle can't
be 0");
}catch (InvalidTriangleException e){
}
try {
Triangle t1 = new Triangle(2,0,3);
fail("InvalidTriangleException because side [var2] of triangle can't
be 0");
}catch (InvalidTriangleException e){
}
try {
Triangle t1 = new Triangle(2,3,0);
fail("InvalidTriangleException because side [var3] of triangle can't
be 0");
}catch (InvalidTriangleException e){
}
}

public void testIsSideNegative() throws InvalidTriangleException{


try {
Triangle t1 = new Triangle(-1, 3, 4);
fail("InvalidTriangleException because first side of triangle can't
be negative");
} catch (InvalidTriangleException e) {
}

try {
Triangle t1 = new Triangle(3, -1, 4);
fail("InvalidTriangleException because second side of triangle
can't be negative");
} catch (InvalidTriangleException e) {
}

try {
Triangle t1 = new Triangle(3, 4, -1);
fail("InvalidTriangleException because third side of triangle can't
be negative");
} catch (InvalidTriangleException e) {
}
}

public void testCorectSide1() throws InvalidTriangleException{


try {
Triangle t1 = new Triangle(9,5,2);
fail("InvalidTriangleException because var1>var2+var3");
}catch (InvalidTriangleException e){
}
}
public void testCorectSide2() throws InvalidTriangleException{
try {
Triangle t2 = new Triangle(2,9,5);
fail("InvalidTriangleException because var2>var1+var3");
}catch (InvalidTriangleException e){
}
}
public void testCorectSide3() throws InvalidTriangleException{
try {
Triangle t3 = new Triangle(5, 2, 9);
fail("InvalidTriangleException because var3>var1+var2");
} catch (InvalidTriangleException e) {
}
}

public void testIsoscelButNotEquilateral() throws InvalidTriangleException {


Triangle triangle = new Triangle(9,9,9);
Boolean expectedResult = false;
Boolean result = triangle.isIsosceles();
System.out.println(result);

public void testIsoscelVar12() throws InvalidTriangleException {


Triangle triangle = new Triangle(7,7,10);
Boolean expectedResult = true;
Boolean result = triangle.isIsosceles();
assertTrue("Triunghiul este isoscel, var1=var2",
expectedResult.equals(result));
}

public void testIsoscelVar13() throws InvalidTriangleException {


Triangle triangle = new Triangle(7,10,7);
Boolean expectedResult = true;
Boolean result = triangle.isIsosceles();
assertTrue("Triunghiul este isoscel, var1=var3",
expectedResult.equals(result));
}

public void testIsoscelVar23() throws InvalidTriangleException {


Triangle triangle = new Triangle(10,7,7);
Boolean expectedResult = true;
Boolean result = triangle.isIsosceles();
assertTrue("Triunghiul este isoscel, var2=var3",
expectedResult.equals(result));
}

public void testScalenVar12() throws InvalidTriangleException {


Triangle triangle = new Triangle(7,7,10);
Boolean expectedResult = false;
Boolean result = triangle.isScalene();
assertTrue("Triunghiul nu este scalen, var1=var2",
expectedResult.equals(result));
}
public void testScalenVar13() throws InvalidTriangleException {
Triangle triangle = new Triangle(7,10,7);
Boolean expectedResult = false;
Boolean result = triangle.isScalene();
assertTrue("Triunghiul nu este scalen, var1=var3",
expectedResult.equals(result));
}
public void testScalenVar23() throws InvalidTriangleException {
Triangle triangle = new Triangle(10,7,7);
Boolean expectedResult = false;
Boolean result = triangle.isScalene();
assertTrue("Triunghiul nu este scalen, var2=var3",
expectedResult.equals(result));
}
@Test
public void testIsEquilateral() {
Triangle triangle = null;
try {
triangle = new Triangle(3, 3, 3);
} catch (InvalidTriangleException e) {
e.printStackTrace();
}
assertTrue(triangle.isEquilateral());
}
}

a)
4)

Conclusion :
Le but de ce travail pratique était passer les étapes de test et de déploiement dans le
cycle de développement d'un programme et en utilisant les outils Java spécifiques à ces
étapes. Je me suis familiarisé avec l'outil JUnit. On a etudie la methode Black-box testing. Je
me suis familiarisé avec l'outil Dependency Injection.

Au bout de tout on peut dire que l’etape de controle est tres importante, parce que cela
peut éviter un risque coûteux à l'avenir.

You might also like