I created a website with jQuery and a lot of ajax requests (json format).
I would like to do a few unit test to test the request on the server side.
Since I used jQuery, I use qUnit, but I have a problem with the testing order ...
For example, I wanted to check this: - create a user => it may be possible
- it is possible to rename a user with a valid name =>
- it is impossible to rename a user using a name =>.
- delete user => could
My code is:
$("button#test").button().click(function() {
module("Module Users");
newName = 'newUserName';
userId = 0;
test("1 Add a user", function() {
stop();
$.getJSON(Request,{'action':'add','table':'users'}
,function(data) {
equal( data.status,"OK", "Answer is OK" );
notEqual( data.item,null, "item is return" );
userId = data.item.id;
start();
});
});
test("2 Rename user", function() {
stop();
$.getJSON(Request,{'action':'modify','table':'users','id':userId,'field':'name','value':newName}
,function(data) {
equal( data.status,"OK", "Answer is OK" );
equal( data.value,newName, "Return value is OK" );
start();
});
});
test("3 Rename user with use name", function() {
stop();
badName = 'usedName';
$.getJSON(Request,{'action':'modify','table':'users','id':userId,'field':'name','value':badName}
,function(data) {
equal( data.status,"Fail", "Answer is Fail" );
equal( data.value,newName, "Return value is previous name" );
start();
});
});
test("4 Remove the user", function() {
stop();
$.getJSON(Request,{'action':'remove','table':'users','id':userId}
,function(data) {
equal( data.status,"OK", "Answer is OK" );
start();
});
});
But the problem is that 1 test is performed, then 4 and 2 and 3 ... (Then, I think the problem is that my tests are not independent)
?
4 1, , ...
?