How to get total amount of tests (incl. taking dat

2019-09-03 05:35发布

问题:

Can anyone tell me how to get (expected) count of all tests / method executions at TestNG (suite) start?

You can easily get the amount of all test methods, but this doesn't count each test method times the amount of the data provider size (each method will be counted once, even if one method is executed 100 times via a data provider).

Unless there is an obvious solution to this, like a simple API call, the key seems to be to figure out the data provider method from the data provider name given in the @Test annotation, which I asked here: How to get data provider method from TestNG data provider name?

Once you know what the data provider method is, you could execute the data provider, and count the amount of data sets. This doesn't seem very efficient, but the tests we're running are not unit tests, so I wouldn't be too worried about executing the data providers twice (it will be a peanut compared to how long the actual tests run).

回答1:

You can use a listener and having your own count logic inside.