Monday 15 February 2010

java - Junit Test Fixture - initialize variables -


It seems that the juneet class variable has different types of rules which I think are managed with test fixtures. needed. So what I want to do is

I have a test suite, a test class and I have two ways (Test 1, Test 2) in this test class, I have class variables in the test class temporary, and I have some Assigning values ​​I want to use this value in test1 and test2 in test1 @RunWith (Suite.class) @ Suite.SuiteClasses ({LoginTest.class}) Public Category SanitySuite {@BeforeClass Public Static Zero Set Up () {BuildTest.seleniumSetUp (); } @AfterClass public static zero tiredown () throws exceptions {BuildTest.seleniumTearDown (); }} Public Category LoginTest {String temp = null; No sign on @Test Public Zero test1 () {temp = "abc"} @Test Public Zero test2 () {system.out.print (temp) // Print Null}}

How to get the value of temp in test2 with test fixtures?

The way the variable works in jUnit is that they are started before each exam If you have specified temp = "abc" in test1, then it will be restarted in test2 run. If you want to start any kind of before each exam, use the setup method.

For unit testing, your objective should be to check the method of the smallest piece of code, usually, one by one. Therefore sharing the variable between test cases is not a good idea. But if you really need to do something like that, then one way can be to club two methods in one method and use the variable set before the other.

No comments:

Post a Comment