Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/01/2012, 18:15
Avatar de Middrel
Middrel
 
Fecha de Ingreso: abril-2005
Mensajes: 835
Antigüedad: 19 años
Puntos: 27
Como implementar códigos a QUnit

Hola buenas tardes,

No estoy seguro si este tema va aquí, pero como es de javascript (JQuery), tal vez no me haya equivocado :)

Estoy empezando con pruebas de utilidad y he estado analizando el código de QUnit, pero en base a los ejemplos que he visto ( 2 + 2 = 1 fail!!, = 2 success!!) del tutorial de QUnit, tengo la siguiente duda:

Por ejemplo, si yo tengo el código de QUnit en HTML:

Código HTML:
<!DOCTYPE html>  
<html>  
<head>  
    <title>QUnit Test Suite</title>  
    <link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen">
    <script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>  
    <!-- Your project file goes here -->  
    <script type="text/javascript" src="myProject.js"></script>  
    <!-- Your tests file goes here -->  
    <script type="text/javascript" src="myTests.js"></script>  
</head>  
<body>  
    <h1 id="qunit-header">QUnit Test Suite</h1>  
    <h2 id="qunit-banner"></h2>  
    <div id="qunit-testrunner-toolbar"></div>  
    <h2 id="qunit-userAgent"></h2>  
    <ol id="qunit-tests"></ol>  
</body>  
</html> 
en las pruebas se ha usado el ejemplo siguiente, guardado en myProject.js:

Código:
// Let's test this function  
function isEven(val) {  
    return val % 2 === 0;  
}  
  
test('isEven()', function() { 
    ok(isEven(0), 'Zero is an even number'); 
    ok(isEven(2), 'So is two'); 
    ok(isEven(-4), 'So is negative four'); 
    ok(!isEven(1), 'One is not an even number'); 
    ok(!isEven(-7), 'Neither does negative seven'); 
 
    // Fails 
    ok(isEven(3), 'Three is an even number');  
})
pero, si yo tengo el siguiente código javascript:

Código:
function getArticulos(art_id){
	/*Se hace la conexión */
	
	$.ajax({
		type: "post",
		url: "../com/datos.cfc", /* URL del archivo .cfc con funciones*/
		data:'method=getArticulos&id_articulos=' + art_id, 
		dataType: "json",
		success: function(resultado){
			var jresultado = JSON.stringify(resultado);
		   	resultado = eval(JSON.parse(jresultado));	
			
		   /* Se empuezan a crear los objetos */
		   	var columna = new Object();
		   		for(var i = 0; i < resultado.COLUMNS.length; i++) {
				columna[resultado.COLUMNS[i]] = i;		
			}
			var id_art = resultado.DATA[0][columna["ATX_ARTICULO"]];
			var descript = resultado.DATA[0][columna["ART_DESCRIP"]];
			var imagen = resultado.DATA[0][columna["IMAGEN"]];
										
		},
		error: function(xhr, textStatus, errorThrown){ //Si hay un error 
		}
	});
}
¿Cómo podría empezar a "testearlo" con QUnit? Es decir, no he trabajado con pruebas unitarias nunca, y es la primera vez que las usaría, ¿cómo tengo que llamar este último código para empezar a hacer las pruebas? En base a esto podría empezar a entender más el funcionamiento de QUnit.

De antemano, les agradezco sus comentarios.