#100DaysOfWeb in Python Transcripts
Chapter: Days 81-84: Unit testing web apps
Lecture: Concept: Web testing pareto principle
0:00 The last main concept I want to cover in this chapter is something called The Pareto Principle. And Pareto Principle is this idea that
0:08 you get 80% of the value out of 20% of the work. This applies to many things. It applies to start ups, it applies to software
0:16 it applies to all kinds of stuff. And so this is an old principle from a philosopher-type person long ago named Pareto.
0:23 The view I take for the Pareto Principle with web apps is if you're starting from nothing if you have a web application and you've already built it
0:31 and it has no tests, and you're like "Oh my gosh, how am I going to take all this time to go back and add all sorts of tests to my code?"
0:38 One thing that you can do really, really easily is just do a basic request to every page that should be available.
0:46 If it doesn't crash, you're like 80% of the way there because, like I said, it doesn't often just give you a little bit of a wrong answer.
0:53 Often what you'll get is, you know "This database connection is wrong." "This object doesn't have this property." It'll completely crash the server.
1:02 So Michael's variation of the Pareto Principle around webcasting is if you just request all the pages you've already tested quite a bit.
1:10 How do we know how to do that? How do we know what those are? Well, if you have a site map that is XML file that looks kind of like this.
1:18 Here's an example from another course that I did and basically it has a bunch of data-driven pages and a few static ones.
1:25 So we put the static ones in there and then use the database to generate all the other pages. Hundreds of thousands of other pages, potentially.
1:33 And that helps Google and Bing search our sites. That's great, but we can also go through this list and go, "alright, well, what are the URLs?
1:41 Let's go and request those." So we probably have a view model that generates those and then we have a controller
1:46 that we'll use to generate those. Super easy and if we have this, we can leverage the site map.
1:52 I already showed you how to do a get request against url so here we could do a get against the url
1:58 to get the XML document. And, by the way, here's a tip. If you don't want to deal with name spaces in XPath queries and you probably don't
2:06 you can just do a quick replace to get rid of that and then we can just go through and test each of them. So we'll load it up into an XML element tree.
2:14 We'll loop over each one of those and then we'll test them, just like we did before. For each url, we'll do a test.
2:20 And here notice, we're assuming that there's going to be some project page that has some data-driven elements. There might be a thousand projects
2:27 or a hundred thousand projects. We really only need to do one request. That's our thinking. One request to that type of page
2:35 or that particular view. It doesn't matter that we test every single potential project. That's what we're saying.
2:41 So we're going to skip out and make this run much faster even if there is tons and tons projects and so on. Alright, and then we just go do a test.
2:47 Go to your app, call get, give it the url say it should be at 200. Alright, so here's my Pareto Principle of testing web apps.
2:54 If you just request every page you're kind of like mostly there.