Hello, all welcome back to the next one. So in this one, we'll continue our discussion on data providers. In last class, we saw that we created a data provider method here, and provided it a name, which we could use in the test method one. Now let's imagine that you have a lot of tests methods inside this test class. So if you have a lot of test methods, like maybe 30, and then you have data provider methods, also in the same class, it becomes a little big and huge, and it's kind of difficult to manage and organize stuff. So sometimes it's a good idea to put all the data providers all the methods, which provides us the data into a completely separate class.
And then we can read the data from there. So what it does it it separates out the actual test methods and the test data. It is a little easier to handle also manage and organize as well. So We can simply do that. So let me actually do this, I'm just gonna create a class up here in the same package. So right click, new class.
And since it's a class, which holds all the data, I'm going to name it as test data, just a little meaningful name and click Finish. What I simply need to do here is I need to copy this method up there. So copy this one, and hit paste here. Once I do this, you can see that it automatically imported the data provider annotation from test NZ. And we are almost done. So I'm gonna actually comment this code out because we copied it there.
And since this annotation is also needed, I'm gonna comment this one up here. But when I run this code, it's actually gonna give me errors right now. So let me just run it and still show you what happens so you understand it in a better way. So the test fail, we can see that it failed. And it was expecting something, but it failed. And I will tell you what happened.
So if you see here, failed test method one. And this method, if I just go towards right, it says it requires either a data provider named inputs, but it could not find it. And that's why it failed. So we copied it inside a new class, why it could not find it. The reason is, if the data provider is in the same class, it can find it automatically. But if it goes in some other class, we need to explicitly tell this either a test annotation about the location of the data provider.
If we don't tell it, it doesn't know where it is. So what we can do here is we can put comma here and do data provider class. Please notice that these small and provider class the first scalars are capital N equals two, we're gonna provide the name of the class. So the name of our class was test. And I'm gonna hit control space, test data, and it's in the test classes packet. So this one, I'm gonna provide an dot class.
Once we do this, it will tell the data provider and other a test annotation where to look for the data. And it will run perfectly fine. Since I have both of these things under the same package, test classes, I don't need to import anything but if you have in different packages, you might have to import the package also, right. So that's about it. Let me right click and run it. And let's see the output.
So run as test Angie. And this time it's again successful we can see input one, input two input one, input two and input one input two. We see our The inputs, so input one, and input two for the first iteration were BMW M three. And for the second iteration, they were rd sx. And then for the third iteration, the inputs were Benz c 300. And it ran the test method one three times.
And we can see it here. And we can see it in the test NZ console also. So the test method one was run three times with the inputs that we can see here. So that's about it. That's what I wanted to show you that we can actually separate out the test methods from the test data. So it will make our test classes a little cleaner, and a little easier to organize and understand.
That's about it guys, please download the code practice and let me know if you have any questions. Thanks for attending this one and I'll see in the next lectures. Thanks