parent nodes: WikiOtros
TDD
Test Driven Development
Author: César TM
Date: 26/10/2017
Source:
http://www.c-sharpcorner.com/UploadFile/dommym/a-test-driven-development-tutorial-in-C-Sharp-4-0/
No: https://msdn.microsoft.com/es-es/communitydocs/alm/sobre-tdd-con-visual-studio
Para C#
En nuestro proyecto que queremos testear
En la explorador de la solución (a la izquierda de la pantalla) con el segundo botón del ratón: ADD->NEW PROJECT. If you can't see the Solution Explorer select from Tools->Options->Projects
Creamos un proyecto de tipo Test con el nombre del proyecto y ese sufijo, en mi caso es: GestionTrabajoDiarioTest.
Hacemos clic con el botón secundario sobre el proyecto (en el panel de la izquierda) y pulsamos "Set as startup project"
Luego con el botón secundario: nuevo test y he usado de wizard que crea tests para todo el código que ya existe (debería hacerse primero el código de los tests y luego el código del programa)
Ejemplo de uno de los ficheros generados:
#include "StdAfx.h"
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
using namespace GestionTrabajoDiario;
namespace GestionTrabajoDiarioTest
{
using namespace System;
ref class CGlobalTest;
/// <summary>
///This is a test class for CGlobalTest and is intended
///to contain all CGlobalTest Unit Tests
///</summary>
[TestClass]
public ref class CGlobalTest
{
private: Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public: property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
{
Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
{
return testContextInstance;
}
System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
{
testContextInstance = value;
}
}
#pragma region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//public: [ClassInitialize]
//static System::Void MyClassInitialize(TestContext^ testContext)
//{
//}
//
//Use ClassCleanup to run code after all tests in a class have run
//public: [ClassCleanup]
//static System::Void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//public: [TestInitialize]
//System::Void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//public: [TestCleanup]
//System::Void MyTestCleanup()
//{
//}
//
#pragma endregion
/// <summary>
///A test for getCurrentUser
///</summary>
public: [TestMethod]
void getCurrentUserTest()
{
String^ expected = "CT";
String^ actual;
actual = CGlobal::getCurrentUser();
Assert::AreEqual(expected, actual);
//Assert::Inconclusive(L"Verify the correctness of this test method.");
}
/// <summary>
///A test for getItemFromList
///</summary>
public: [TestMethod]
void getItemFromListTest()
{
String^ theStatus = "HECH";
String^ theTicketNumber = "1706221615279";
bool deleteItem = false;
String^ expected = "HECH 1706221615279-VAL-Apostilla_y_legalizacion_por_titulo_y_certificación :CLIE:Solicitud:#D:MN:";
String^ actual;
actual = CGlobal::getItemFromList(theStatus, theTicketNumber, deleteItem);
Assert::AreEqual(expected, actual);
Assert::Inconclusive(L"Verify the correctness of this test method.");
}
/// <summary>
///A test for getMasterList
///</summary>
public: [TestMethod]
void getMasterListTest()
{
String^ estado = "HECH";
List<String^ >^ expected = CGlobal::hechos;
List<String^ >^ actual;
actual = CGlobal::getMasterList(estado);
Assert::AreEqual(expected, actual);
Assert::Inconclusive(L"Verify the correctness of this test method.");
}
/// <summary>
///A test for replaceMetaCharsWithChar
///</summary>
public: [TestMethod]
void replaceMetaCharsWithCharTest()
{
String^ theString = "MÚRCÍÉLÁGÓ_múrcíélágó:ñ:Ñ:Çç[]hòlà";
wchar_t theChar = '_';
String^ expected = "MURCIELAGO_murcielago_n_N_Cc__hola";
String^ actual;
actual = CGlobal::replaceMetaCharsWithChar(theString, theChar);
Assert::AreEqual(expected, actual);
//Assert::Inconclusive(L"Verify the correctness of this test method.");
}
/// <summary>
///A test for setItemInList
///</summary>
/*public: [TestMethod]
void setItemInListTest()
{
String^ theStatus = "HECH";
String^ theFullItemString = "";
CGlobal::setItemInList(theStatus, theFullItemString);
Assert::Inconclusive(L"A method that does not return a value cannot be verified.");
}*/
};
}
namespace GestionTrabajoDiarioTest {
}
_________________________________________________________________________________________________________
WikiOtros [camelCaseWordsEnabled: false]