I have a Junit test class with two tests in it. test 1 will add an element to an ArrayList and passes it to the main class to do some logic and returns true. Test two should use the same arrayList and calls the same main class do the same logic but by the time the list comes to second test methods, its getting null.
I declared it as class variable. My questions is.. when I assign values to a class variable in a test method, will I not have access to the values in next test method? If yes, how should i retain the values.
Thanks, Mahi
The way variables work in jUnit is that they get initialized before each test. So if you added value x to a list in Test1, it won't be there when you run Test2. If you want to some kind of initialization before each test, use the setup method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With