EPS MTG Lab01 Minicalc

Páginas: 11 (2719 palabras) Publicado: 13 de septiembre de 2015
MATERIALES DE TRABAJO DE EVOLUCIÓN Y PRUEBAS DE SOFTWARE

PRÁCTICA DE LABORATORIO N˚ 01
Sección : …………………..
Docente : Daniel Gamarra Moreno
Unidad ; ………
Semana : …….
Instrucciones

Apellidos
Nombres
Fecha

: ………………………………..
: ………………………………..
: …/…/… Duración: …….

: Desarrolle las actividades solicitadas.

PRUEBAS UNITARIAS CON NUNIT
PROYECTO MINICALC
EJERCICIO 1: CREAR SOLUCION Y PROYECTOS
1.Crear una solución en blanco llamado MiniCalc.

2.

Añadir un proyecto C# Windows Forms Application, llamado MiniCalc.

3.

Añadir un proyecto C# Unit Test Project, llamado CalcTest.

4.

Renombrar la clase UnitTest1 por CalcTest.

5.

Inserte el siguiente código en la clase CalcTest.:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CalcTest
{
[TestClass]
public classUnitTest1
{
[TestMethod]
public void PruebaFalla()
{
Console.Out.WriteLine("Llamando a PruebaFalla");
Assert.Fail("Esta prueba falla!");
}
[TestMethod]
public void PruebaExito()
{
Console.Out.WriteLine("Llamando a PruebaExito");
Assert.IsTrue(true,"Esta prueba es un exito!");
}
}
}

6.

Construya la solución (Biuld Solution).

7.

Corra la pruebas.

EJERCICIO 2: ESCRIBIR UNA PRUEBA Y PROBAR ALGUNAFUNCIONALIDAD
1.

Añada el método TestAdd a la clase CalcTest.
[TestMethod]
public void TestAdd()
{
Console.Out.WriteLine("TestAddition called");
Calculator testCalc = new Calculator();
//test for case of zeros'
Assert.AreEqual(0, testCalc.Add(0, 0), "Adding 0 to 0 should produce 0");
//test that param ordering isn't important

1

MATERIALES DE TRABAJO DE EVOLUCIÓN Y PRUEBAS DE SOFTWAREAssert.AreEqual(1, testCalc.Add(1, 0), "Adding 1 to 0 should produce 1");
Assert.AreEqual(1, testCalc.Add(0, 1), "Adding 0 to 1 should produce 1");
//test for non zero case
Assert.AreEqual(3, testCalc.Add(1, 2), "Adding 1 to 2 should produce 3");
int nResult;
try
{
nResult = testCalc.Add(int.MaxValue, int.MaxValue);
Assert.Fail("Should throw a ResultOutofRangeException");
}
catch (ResultOutOfRangeException){
}
testCalc = null;
}

2.

Añada la clase Calculator.

3.

Crea el esqueleto de la clase Calculator y la excepcion.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MiniCalc
{
public class ResultOutOfRangeException : ApplicationException
{
}
public class Calculator
{
public int Add(int a, int b)
{
return 0;
}
}
}

4.Remueva los métodos PruebeFalla y PruebaExito de CalcTest.

5.

Añadir la referencia MiniCalc a CalcTest.

6.

Inserte la directiva “using MiniCalc;” en el archivo CalcTest.cs

7.

Compila el proyecto (Build Solution).

8.

Corra la prueba y ….. falla la prueba porque falta la funcionalidad.

9.

Modifica el método Add de Calculator, para darle funcionalidad.
public int Add(int a, int b)
{
return a +b;
}

10. Falla la prueba debido a que no se lanza la excepción.
11. Modifica el método Add, que incluye la excepción.
public int Add(int a, int b)
{
int result;
result = a + b;
if (result < 0)
{
ResultOutOfRangeException rangeEx = new ResultOutOfRangeException();

2

MATERIALES DE TRABAJO DE EVOLUCIÓN Y PRUEBAS DE SOFTWARE
throw rangeEx;
}
return result;
}

12. Compila el proyecto (BuildSolution) y corra el NUnit.

EJERCICIO 3: CONECTE LA LOGICA DE NEGOCIO A LA INTERFACE DE USUARIO
1.

Crea la siguiente interface:

Figura 1. Interface de usuario – Proyecto MiniCalc.

Añada dos controles NumericUpDown llamados NumberA y NumberB, una etiqueta con el texto +, un botón
llamado EqualsButton con el texto = y una etiqueta llamada Result (mostrado como 3 en la figura).
2.

Doble click en elcontrol EqualsButton para generar el evento handler. En este evento inserte el siguiente código.
private void EqualsButton_Click(object sender, EventArgs e)
{
try
{
Calculator calc = new Calculator();
Result.Text = (calc.Add((int)NumberA.Value, (int)NumberB.Value).ToString());
}
catch (ResultOutOfRangeException)
{
Result.Text = "Out of Range";
}
}

3.

Construya la solución (Biuld Solution) y...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • LAB01
  • LAB01
  • Lab01
  • Las EPS
  • La eps
  • eps
  • mtg r4t
  • Proyecto mtg

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS