DataProviders - Part 2

4 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€66.52
List Price:  €95.03
You save:  €28.51
£55.29
List Price:  £78.99
You save:  £23.70
CA$98.01
List Price:  CA$140.02
You save:  CA$42.01
A$108.26
List Price:  A$154.67
You save:  A$46.40
S$94.28
List Price:  S$134.69
You save:  S$40.41
HK$544.68
List Price:  HK$778.14
You save:  HK$233.46
CHF 62.24
List Price:  CHF 88.92
You save:  CHF 26.68
NOK kr781.73
List Price:  NOK kr1,116.81
You save:  NOK kr335.07
DKK kr496.25
List Price:  DKK kr708.95
You save:  DKK kr212.70
NZ$119.48
List Price:  NZ$170.70
You save:  NZ$51.21
د.إ257.07
List Price:  د.إ367.25
You save:  د.إ110.18
৳8,430.24
List Price:  ৳12,043.71
You save:  ৳3,613.47
₹5,907.88
List Price:  ₹8,440.19
You save:  ₹2,532.31
RM313.59
List Price:  RM448
You save:  RM134.41
₦117,896.75
List Price:  ₦168,431.15
You save:  ₦50,534.40
₨19,601.13
List Price:  ₨28,002.81
You save:  ₨8,401.68
฿2,456.64
List Price:  ฿3,509.64
You save:  ฿1,053
₺2,405.01
List Price:  ₺3,435.88
You save:  ₺1,030.86
B$408.16
List Price:  B$583.12
You save:  B$174.95
R1,278.38
List Price:  R1,826.34
You save:  R547.95
Лв129.87
List Price:  Лв185.54
You save:  Лв55.66
₩98,547.64
List Price:  ₩140,788.38
You save:  ₩42,240.74
₪262.83
List Price:  ₪375.48
You save:  ₪112.65
₱4,119.38
List Price:  ₱5,885.08
You save:  ₱1,765.70
¥10,926.10
List Price:  ¥15,609.38
You save:  ¥4,683.28
MX$1,438.75
List Price:  MX$2,055.45
You save:  MX$616.69
QR257.25
List Price:  QR367.52
You save:  QR110.26
P957.42
List Price:  P1,367.80
You save:  P410.38
KSh9,063.70
List Price:  KSh12,948.70
You save:  KSh3,885
E£3,455.33
List Price:  E£4,936.40
You save:  E£1,481.07
ብር8,611.91
List Price:  ብር12,303.26
You save:  ብር3,691.35
Kz63,807.12
List Price:  Kz91,156.94
You save:  Kz27,349.81
CLP$68,583.90
List Price:  CLP$97,981.20
You save:  CLP$29,397.30
CN¥506.99
List Price:  CN¥724.30
You save:  CN¥217.31
RD$4,249.83
List Price:  RD$6,071.45
You save:  RD$1,821.61
DA9,380.49
List Price:  DA13,401.28
You save:  DA4,020.78
FJ$159.39
List Price:  FJ$227.72
You save:  FJ$68.32
Q545.12
List Price:  Q778.78
You save:  Q233.65
GY$14,759.55
List Price:  GY$21,085.97
You save:  GY$6,326.42
ISK kr9,759.40
List Price:  ISK kr13,942.60
You save:  ISK kr4,183.20
DH701.60
List Price:  DH1,002.33
You save:  DH300.73
L1,265.07
List Price:  L1,807.32
You save:  L542.25
ден4,092.25
List Price:  ден5,846.32
You save:  ден1,754.07
MOP$565.22
List Price:  MOP$807.49
You save:  MOP$242.27
N$1,267.59
List Price:  N$1,810.92
You save:  N$543.33
C$2,596.85
List Price:  C$3,709.94
You save:  C$1,113.09
रु9,521.24
List Price:  रु13,602.36
You save:  रु4,081.11
S/267.43
List Price:  S/382.06
You save:  S/114.63
K283.56
List Price:  K405.11
You save:  K121.54
SAR262.97
List Price:  SAR375.69
You save:  SAR112.72
ZK1,929.77
List Price:  ZK2,756.93
You save:  ZK827.16
L331.05
List Price:  L472.96
You save:  L141.90
Kč1,682
List Price:  Kč2,402.96
You save:  Kč720.96
Ft27,138
List Price:  Ft38,770.23
You save:  Ft11,632.23
SEK kr772.63
List Price:  SEK kr1,103.81
You save:  SEK kr331.17
ARS$69,869.10
List Price:  ARS$99,817.28
You save:  ARS$29,948.18
Bs487.60
List Price:  Bs696.60
You save:  Bs209
COP$315,227.33
List Price:  COP$450,344.06
You save:  COP$135,116.73
₡36,031.09
List Price:  ₡51,475.19
You save:  ₡15,444.10
L1,781.45
List Price:  L2,545.04
You save:  L763.59
₲550,680.18
List Price:  ₲786,719.69
You save:  ₲236,039.51
$U2,973.65
List Price:  $U4,248.26
You save:  $U1,274.60
zł288.46
List Price:  zł412.11
You save:  zł123.64
Already have an account? Log In

Transcript

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

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.