java - JUnit 4: Test case returns an object used in other tests in the test suite -



java - JUnit 4: Test case returns an object used in other tests in the test suite -

i have created several tests cases application, these chained in single test suite class.

however, pass object created in first test others.

to clearer, first test tests class creates complex object info coming database. others test methods of object itself.

here how define test suite class:

package tests.testsuites; import tests.test1; import tests.test2; import org.junit.runner.runwith; import org.junit.runners.suite; import org.junit.runners.suite.suiteclasses; @runwith(suite.class) @suiteclasses({ test1.class test2.class }) public class datatestsuite { }

but have somewhere:

myobject obj=test1.testcreation(); test2.testmethod(obj);

how can combine regular junit testsuite class definition need pass created object other test?

edit

for information, test suite launched in test runner class. class helps formatting results , creates custom log file.

this how calls test suite:

public class metexploretestrunner { public static void main(string[] args) { result result=junitcore.runclasses(datatestsuite.class); if(result.wassuccessful()){ system.out.println("all tests succesful "); }else{ for(failure failure:result.getfailures()){ system.out.println(failure.tostring()); } } } }

do not that. each test should independent of others. can run tests singly, debug them, , each test easier understand. also, junit runs tests in arbitrary order; can not guarantee object created before used.

if several tests utilize similar object, consider extracting code creating shared private method of test class. if many tests utilize object, consider making test fixture set @before method.

java unit-testing junit

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -