DjangoCon 2015

Introducción a los tests de la parte del cliente

Mark Lavin  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

what does repeat all of the things they just said I work for cactus group I'm the co-author of lightweight Django you can find me on twitter i'm dr. oh yes I'm em Lavin on github and the rest of the internet if you can help me acquire the M lab

and Twitter account like come see me after be interested so what's the what's the goal of this talk the gold this talk is to get you started writing tests from a practical standpoint this isn't supposed to be an in-depth review of all available

JavaScript testing tools and I'm not here to convince you to do testing like that argument I don't think needs to be made anymore especially not in this this community so the workflow is I'm going to show you a little example project I'm going

to show you some integration tests for that project and then we'll go through some unit tests for that project so what are we going to test today this is a project that lives on file AP IM lavin org and the source code is available on my github account

it's a minimal REST API using JSON web tokens for auth it does drag and drop file uploads there's a limit please don't try to upload like 100 gigs my server please the front end uses backbone I'm not going to show you any of the code for the

views any of the backbone code I'm only going to show you the tests if you want to take the time and review the project code itself at do so in your own time it looks like this you login there's a guest login when you after you login you see this blob

and an empty line because they didn't spend any time styling this when you drag a file it's there and then there's a little X and you can delete it that's what the project looks like on the back end it looks like this there's not that many

views there's you know the API route which renders the single page app there's a an endpoint to exchange an API token of the username password for an API token you can get uploads to list all uploads you can post a new upload you can get uploads like

details for single upload you can delete an upload there's no put for updating yeah it's super restful but users don't care about rest like users don't care about how restful the back end is they want to do things on the site they want to log

into the site they want to navigate around they want to submit data they want to see their data and so those are the things that you want to test to make sure that this works as expected and that's what selenium is really good at selenium drives a browser

and you can interact with the Dom you can fill in data you can click links you can assert things about the current state of the Dom some basic selenium set up this almost comes straight out of the Django docs is to use the live static server test case and

do some setup tear down of the selenium webdriver the setup and teardown can be a little slow that's why it's done once per class rather than per test that means you don't get perfect test isolation and it can lead to problems I like phantom j/s

for the driver it's a headless webkit browser you can install with NPM you could replace this with Firefox or Chrome or ie or you may want to run your tests against all of them that's all available options phantom Jas also works well it's installed

[ ... ]

Nota: se han omitido las otras 1.649 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.