问题
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.
来源:https://stackoverflow.com/questions/31238604/how-to-get-total-amount-of-tests-incl-taking-data-providers-into-account-at-t