Crear proyecto maven
Crear un proyecto Maven desde NetBeans

Nombre: myjenkins

Crear una clase Calculadora y los test
public class Calculadora {
public Integer sumar(Integer a, Integer b){
return a +b;
}
public Integer restar(Integer a, Integer b){
return a -b;
}
public Integer multiplicar(Integer a , Integer b){
return a *b;
}
public Double dividir(Integer a, Integer b){
return a.doubleValue() /b.doubleValue();
}
}
Crear el Test usando JUnit
File--> New -->Unit Test

Seleccionamos la clase a crear los test

Se genera la clase CalculadoraTest.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.avbravo.myjenkins;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
*
* @author avbravo
*/
public class CalculadoraTest {
public CalculadoraTest() {
}
@org.junit.jupiter.api.BeforeAll
public static void setUpClass() throws Exception {
}
@org.junit.jupiter.api.AfterAll
public static void tearDownClass() throws Exception {
}
@org.junit.jupiter.api.BeforeEach
public void setUp() throws Exception {
}
@org.junit.jupiter.api.AfterEach
public void tearDown() throws Exception {
}
/**
* Test of sumar method, of class Calculadora.
*/
@org.junit.jupiter.api.Test
public void testSumar() {
System.out.println("sumar");
Integer a = null;
Integer b = null;
Calculadora instance = new Calculadora();
Integer expResult = null;
Integer result = instance.sumar(a, b);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of restar method, of class Calculadora.
*/
@org.junit.jupiter.api.Test
public void testRestar() {
System.out.println("restar");
Integer a = null;
Integer b = null;
Calculadora instance = new Calculadora();
Integer expResult = null;
Integer result = instance.restar(a, b);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of multiplicar method, of class Calculadora.
*/
@org.junit.jupiter.api.Test
public void testMultiplicar() {
System.out.println("multiplicar");
Integer a = null;
Integer b = null;
Calculadora instance = new Calculadora();
Integer expResult = null;
Integer result = instance.multiplicar(a, b);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of dividir method, of class Calculadora.
*/
@org.junit.jupiter.api.Test
public void testDividir() {
System.out.println("dividir");
Integer a = null;
Integer b = null;
Calculadora instance = new Calculadora();
Double expResult = null;
Double result = instance.dividir(a, b);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
}
Ejecutar el Test la primera vez
Clic derecho en CalculadoraTest.java --> Test File

ejecución
La primera vez los test deben fallar

Last updated
Was this helpful?