Hello all welcome back to the next one. In this one, we'll take a look at prioritizing the test cases in test in G, or here we got our Eclipse. And I've created a class and named it as test Angie underscore priority. It is a usual test class that we have, by now you guys are already aware of before class after class. So this is gonna run once before class. This is gonna run once after class.
And then I have three test methods. test method one, test method two and test method three. And initially, we learned that testing t runs test cases in the order of alphabetical preference. But what if I want to make sure that one of my test method runs first and one of my test method runs second? And they do not depend on what name they have? Right?
So I should have some way to control the order of execution, instead of relying on test energy, alphabetical order. So for now, by default, let's right click here run as test in G test. And let's see the order. So it ran test method 123 in this particular order, this is the default one. Now let's see how we can change it. So after the at the rate test annotation, we have a lot of attributes that we can use.
One of them is priority. So PRIOR i t y equals to zero so basically the priority starts from 00 means the first, as always in programming in arrays in list we usually have index starting from zero, same thing happens with Friday. So they start from zero. So now what What I'm doing here is I'm giving priority zero to test method three, which means even though this is last in execution, the default execution, you can see that even though it is last by default execution, it should run the first one right the first time. And I'm just going to copy the same thing up here. And for those tests, method two, I'm going to give one.
And for test method one, I'm going to give two. So basically, now we have said the primaries. And these are the primary. So obviously, this is to help us so we don't want to put zero to two places, right? We know what we are doing. We are trying to test our application.
We're not trying to test test ng g here, right? So I think, yeah, we are not trying to test as we are not trying to verify what testing is doing. We're trying to test our application and these things are for our benefit. So Use them as your need. To be honest, we don't really use this pride feature a lot, because later I'll be discussing a few other features which are more useful than priety. Because it doesn't make sense to make your test dependent kind of on each other like, only this test method should run first, and this test method should run second.
This doesn't make sense. We should not define or we should not design test cases like that, they should be independent, they should run independently, irrespective of the order they are running. My test method one may be running at the first test, or it may be running as the last test, it should not matter. It should run independently and should not be affected by where it's running. So But still, if we have a Friday, then we can use this feature. So let me just save it and right Click Run as test in G. And now we can see test method three was run before, and then test method two and then test method one.
So this way prior is really useful if we really want to run test cases in a particular order. And in general, the practice is to make test cases independent. So we don't have to really make dependent test cases or run them in a particular order. But there may be scenarios depending on the application and particular feature that we are testing that we might need particular test case to run at the first occurrence and then the particular test case at the second time and then the particular test case at the third time. So basically, in a particular order, we might have a scenario like that. So if we have a scenario, then this is really helpful.
Alright guys, so that's pretty much about it. And please get the file downloaded and practice as much as you can let me know if you have any questions and thanks for attending this one else in the next lectures, guys, thanks