开发者

Test problem using JUnitPerf

开发者 https://www.devze.com 2022-12-28 06:16 出处:网络
I\'m writing a JUnit test using JUnitPerf. Here, I want to generate some entries and use them to update a database. To test the capacity of the database, I want several test to run simultaneously or r

I'm writing a JUnit test using JUnitPerf. Here, I want to generate some entries and use them to update a database. To test the capacity of the database, I want several test to run simultaneously or randomly, so I use, for example:

Test loadTest = new LoadTest(testCase, n);

But, still, I have to insure that in each test, a different update source will be us开发者_开发知识库ed so that a different entry in the database will be updated.

So my question is how can I realize this?

Thanks a lot Allen


You can add a static AtomicInteger as a seed to your test case and increment this as part of the test, Use the seed as the basis for generating your test entry for that test. In the simplest case, the seed is used as an index to look up the test data in an array.

E.g.

class MyTestCase extends TestCase
{
    static AtomicInteger seed = new AtomicInteger();

    public void testUpdateEntry()
    {
       int seedValue = seed.getAndIncrement();

       // generate entries from seed
       // write entries to db
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号