Lleva tus pruebas unitarias al siguiente nivel
¡Hola Comunidad
Es el momento de llevar vuestras pruebas unitarias al siguiente nivel, con la nueva funcionalidad iris-TripleSlash!
Simplemente añade una descripción a la clase, con etiquetas especiales como:
- beforeAll
- beforeOne
- afterAll
- afterOne
TripleSlash lo convertirá en:
- OnBeforeAllTests
- OnBeforeOneTest
- OnAfterAllTests
- OnAfterOneTest
¡Y eso no es todo! La nueva abreviatura punto doble permite llamar métodos fácilmente y simplificar el código, por ejemplo:
///<example>
/// Write ..TheAnswerForEverything()
/// 42
///</example>TripleSlash generará automáticamente una prueba, como esta:
Method TestTheAnswerForEverything()
{
Do $$$AssertEquals(##class(dc.sample.ObjectScript).TheAnswerForEverything(), 42)
}Configuración y Eliminación
/// también puede ser usado para definir métodos para la configuración y eliminación del entorno de pruebas unitarias.
Veamos cómo hacerlo usando nuestra anterior clase de prueba:
/// A simple class for testing purpose.
///
/// <beforeAll>
/// Write "Executes once before any of the test methods in a test class execute. Can set up a test environment."
/// Return $$$OK
/// </beforeAll>
///
/// <afterAll>
/// Write "Executes once after all of the test methods in a test class execute. Can tear down a test environment."
/// Return $$$OK
/// </afterAll>
///
/// <beforeOne>
/// Write "Executes immediately before each test method in a test class executes."
/// Return $$$OK
/// </beforeOne>
///
/// <afterOne>
/// Write "Executes immediately after each test method in a text class executes."
/// Return $$$OK
/// </afterOne>
Class dc.sample.ObjectScript
{
...
}Después de ejecutar ///, nuestra clase de prueba unitaria ha añadido los métodos OnAfterAllTests(), OnAfterOneTest(), OnBeforeAllTests() y OnBeforeOneTest():
Class iris.tripleSlash.tst.ObjectScript Extends %UnitTest.TestCase [ Not ProcedureBlock ]
{
Method OnAfterAllTests() As %Status
{
Write "Executes once after all of the test methods in a test class execute. Can tear down a test environment."
Return $$$OK
}
Method OnAfterOneTest() As %Status
{
Write "Executes immediately after each test method in a text class executes."
Return $$$OK
}
Method OnBeforeAllTests() As %Status
{
Write "Executes once before any of the test methods in a test class execute. Can set up a test environment."
Return $$$OK
}
Method OnBeforeOneTest() As %Status
{
Write "Executes immediately before each test method in a test class executes."
Return $$$OK
}
...
}Agradecimientos
Muchas gracias de nuevo a toda la Comunidad por su apoyo continuo al desarrollo de nuestras aplicaciones. Vuestros comentarios y sugerencias son inestimables para nosotros.