Le 24/09/12 06:18, Niklas Laxström a écrit :
I'm writing unit tests for one of Translate classes.
In the setUp I need to create few pages, but I need to also control the user ids of the revisions. This seems to work well except for two things:
- dataProvider methods are called *before* setUp, so I cannot use the
user ids I have stored in setUp.
- setUp and tearDown are called for *every* item in the dataProvider.
This seems very wasteful - no wonder the tests takes minutes or so to run.
A data provider give a stream of cases that will be used as an independent test. Kind of save you from copy pasting the same test function over and over.
setUp() is a method called before each test, so it is indeed called before each of the cases provided via a data provider. Similarly, tearDown() is called after each test.
This just doesn't make any sense to me. I'm considering to stop using @dataProvider in this case - any other ideas?
The code in setUp is something like this:
$title = Title::makeTitle( NS_MEDIAWIKI, 'Key1/fi' ); $user = User::newFromName( 'Translate test user 1' ); $user->addToDatabase(); WikiPage::factory( $title )->doEdit( 'trans1', __METHOD__, 0, false, $user ); $this->user1 = $user;
One possibility would be to only set it once using the setUpBeforeClass() and tearDownAfterClass(). Those are only run once in the class. So you could create a new test file having a class dedicated to this test.
You could probably skip the addToDatabase() call if the user is already in there. Note your code will produce an edit for any case.
Can you possibly send the code in Gerrit so we can have a look at it?