c# - Testing web API service -
i'd test methods of given web api service. adding test project, instantiating controllers , testing methods. however, don't want test methods, i'd test request , response. similar in java, this:
private httpserver server; @before public void before() { this.server = servidor.initializeserver(); } @after public void stopserver() { server.stop(); } @test public void testaquebuscarumcarrinhotrazocarrinhoesperado() { client client = clientbuilder.newclient(); webtarget target = client.target("http://localhost:8080"); string conteudo = target.path("/carrinhos").request().get(string.class); carrinho carrinho = (carrinho) new xstream().fromxml(conteudo); assert.assertequals("rua teste", carrinho.getrua()); }
now, have run web api project start server, run tests. there way of writing code this?
yes can , there called selfhosted web api see given link can build test project on same lines.
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api
Comments
Post a Comment