samedi 28 mars 2015

How can i test my own Http Server maded on DartLang

first time i'm posting a question here and i should ask sorry about my english. I'm coding a web server with dart and i'm trying to do some unit testing on it but i can't figure out how can i do that on the right way...


Actually i'm doing this on the main test file:


void main() { startApp().then((_) { WebbErrosBack_test.defineTests(); }); }


My startApp code:


Future startApp() { return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 80).then((server) { Routes.doRoute(server); }); }


My Routes.doRoute code:


static void doRoute(server) { var router = new Router(server); //home ==> new UrlPattern(r'/'); //homeView ==> req.response.write('Hi'); router.serve(home).listen(homeView); }


My test WebbErrosBack_test.defineTests code:


void defineTests() { group('main tests', () { test('Code 200', () { Future<http.Response> future = http.get( "http://127.0.0.1/"); expect(future.then((http.Response e) => e.statusCode), completion(equals( 200 ))); }); }); }


Problem 1: The test runs fine, but at the end, the server still up, anyone knows a way to kill the server at the end of ALL tests?


Problem 2: i'm doing the test the right way?


Ty


Aucun commentaire:

Enregistrer un commentaire