Re: Setting an instance variable in a Test Class
Posted By:
Robert_Lybarger
Posted On:
Saturday, February 16, 2008 09:54 PM
I believe junit runs each test method in a different instance of the class, which is actually desirable to prevent effects of one test from influencing another. In your case, you could probably make 'i' a static variable, but the better solution for unit testing DB query code would be to create a database setup script that populates known-good material so that 'secondTest' has a better chance of being properly initialized when it runs, and does not depend on success/failure of firstTest. (Otherwise, you haven't really written two unit tests... you've written one test split improperly across two methods.)