Hello all welcome back to the next one. So we have been talking about writing one test class and writing before methods before class and everything. So right now it's time to understand how usually test cases and test classes are created. We usually have a lot of test cases. So for now, we are considering one test case as one test method. But we have a lot of test cases and it's not possible to put every single test case into one test class.
So, usually, if whether we are doing Selenium WebDriver, or any other kind of automation, even rest API's or any back end automation, we have a lot of test classes and test classes are usually created based on the functionality. Imagine for an example of web automation, which is Selenium WebDriver. You have 10 pages on your web. application, you would want to create 10 different test classes for testing those 10 pages. So that's why you would create a lot of test classes and the test cases related to that functionality would go in a particular test class. Because of this, all those test classes in combination are known as test suite.
And not just those physical test classes are known as test suite. Basically, a test suite can be referred to as a virtual or logical assignment. Also, we may want to pick three test classes and call it one test suite. And it depends on what is our intention of testing. There could be a smoke test suite, which kind of test some basic particular things and does some quick checks that is usually known as smoke test. There's a regression test suite and that is kind of full fledged verification of all the features of the application.
So regression test suite is one thing and smoke test suite is one thing. Likewise, you can have different kind of test suites, like some for build, validation, test suite and some other it depends on your application and your organization. Leaving that thing aside, what we want to understand is now let's assume we have more than one test class, and we want to run multiple test classes in a single shot. How do we achieve that, till now we have been running one test class, but now we want to run more than one test class. And we want to understand how we can do that. So there is a concept of test suites in test engine which is really very handy and we can use that.
So I have created one test class a test a new test class one. There is a usual setup the before class and This is after class, before method and after method. And then couple of test methods test method one and test method two. And I should actually say the name of the test class here, so it will be more specific. So when we see the output we will understand from which test class things are coming. Now, I created this class ahead of time, but I wanted to create one in front of you.
This was just to save a little bit of time. So, what I'm gonna do here is click on the right click on the packet, go to new and go to other as usual, type test NZ, create a test in G class. And I'm going to select before method after method before class and after class for now, and click Finish. So I forgot to change the name but that's okay. We can always We can always refactor the name. So let's refactor it.
So we have some meaningful name. So refactor, rename, and test in G test class to. This is the name we gave. So it creates a test method. By default, it creates a before method after method before class and after class method. I can do select all and Command Shift F, or Ctrl, Shift F to format it a little bit.
Now I actually want to copy all these methods from here. So we can just save a little bit of time. In typing these things. It's basically doing nothing. We're just printing out statements, which shows that this test method is getting run. And inside the test method, there would be obviously functionality to test a particular feature that pertains to your application.
So this method is up there And now, we will just change the name of the class. So let's just do this. And maybe we can add the name of the class to other methods also. So that we can just easily identify that this statement is getting printed from this particular class. And I can do the same thing to this class as well. And obviously, we can do to every method.
Let's do for before class and after class also, because everything is going to get printed. And since this is almost a similar print statement, we will we may get just confused a little bit. So it's, it's good to always have clear and organized stuff. So we don't get confused by these things. All right, so since now, we have typed in everything we have to test classes and The usual way is obviously we just go ahead and right click one of the file and click run as test Angie. And it runs the test engine class.
But do I want to do this separately for every class? No, right? I want a mechanism, which I can use to run both the classes together. So for that, we need to create a test, Angie, XML file, and test Angie has capabilities to read that file and it will run both the test classes for us how we do that, in our project, we'll go to the project I'm not going to source I'm not going to package I'm going to project. I'm going to right click here, new. And then I'm going to add a file.
Let's name it as test and G and dot XML. So basically we are creating an XML file here. And the file is created down here you can actually name it anything, but it has to be an XML file in that we will create a format so we want to create a test suite so I'm just gonna say suite name and let's name it as maybe regression test suite. So, this is a regression test suite for us. And inside suite we want to name test and name that test also something so maybe I can say it here as application test. And this guy is the test these this is the format of this file.
So please make sure that you type correctly everything should be proper there should be no typos and should follow the format. Inside this we will tell test Angie, which classes want to include in this suite and in this test group here, I'm gonna add classes. And this is gonna be again, one more block. Inside classes, we will add individual class. So class and I'm gonna name it. So the name will be actually the full name of your class, so it should include package.
So the package we have is test classes. No typos, please make sure that you include it correctly. dot the name of the class. So the name of the class is test, Angie underscore test class one. And we don't need to include dot java. So this is the name of the class.
Now this is our class one. And we can actually copy this statement and we can include one more class here and change the name to test classes dot test. engender Code test class two. So what we did here is we created a test suite. This name can be anything, you can name it, whatever you like. This name can be anything, you can name it whatever you like.
But this name has to be the proper name of the class, including the package name. So our package name is test classes, and then dot, because it is needed the name of the class exact name of the class. So this is our first test suite. I can save this file. Now since we have test Angie plugin installed, I can just right click on this and go to run. And this will show me this option test in G Suite.
And if I click this guy, it ran both the classes Did you guys notice that? how cool that is? it picked up now it's not the default suite. Did you notice when we were running individual classes it was saying default suite because there was nothing that we provided. Now we provided the name of the sweet name of the test. So it will pick everything from here.
So it picks regression test Wait, whatever we named that test is application test. This is class one, method one for class from class one, method two from class two. And this is again, both the methods from class two, sorry, class one and class two, all the methods are run, if we go to console, we can see both the classes running. So, from test end class one, this is before class, this is before method, then it's the test method one, then it's, again after method. And again before method. So, basically it's doing everything, it's all the print statements, it's printing every single thing.
So all the print statements are here and everything is executed successfully. So this is really the way this is how we actually execute all the classes. We never go ahead and play Individual classes usually will have different test weights in which there would be numerous classes. So, usually we'll have this kind of format, we can create these kind of test suites, we can create any number of test suites like that, there is no limit. And every test suite can include different classes. And we can actually put methods also here under a class.
So what that helps us if let's assume that you don't want to run a particular method from the class, you don't, you just don't include it here. And it will only run the methods that are included here that we can cover later. But for now, please understand that this is how we create a test suite, we can create an XML file and run it it will run all the included test classes for us, whatever be included in the XML file. So that's about it. Please go ahead, practice this and let me know if you have any Any questions? Thanks a lot for attending this one.
I'll see you in the next lectures.