tempto icon indicating copy to clipboard operation
tempto copied to clipboard

@BeforeTest / @AfterTest in parent classes

Open electrum opened this issue 7 years ago • 4 comments

Are @BeforeTestWithContext / @AfterTestWithContext supposed to work in parent classes? The method TestInitializationListenerinvokeMethodsAnnotatedWith() uses getDeclaredMethods() which only finds methods on that exact class. Should it look for methods recursively in the super classes?

electrum avatar Mar 30 '17 23:03 electrum

IMO it should wok. I mean it should check super class.

However, till now nobody got to this issue and we had really complicated use cases with usage of Teradata and Presto together. Have you considered to use composition over inheritance?

kokosing avatar Mar 31 '17 06:03 kokosing

My use case was the LDAP tests which have a bunch of @Inject fields (test parameters). Basically, I wanted to reuse that in the parent class. Can that be done with composition?

Normal TestNG inheritance is rather difficult to follow and somewhat buggy (or perhaps I don't understand it because it's not documented), so I could agree with not wanting to support inheritance.

However, if we choose not to support that, it would be helpful to scan the parents for annotations and fail explicitly, rather than trying to figure out what happened when you get NPE or similar due to the setup not running.

electrum avatar Mar 31 '17 07:03 electrum

I think it is always possible to use composition ; )

Do you mean: https://github.com/prestodb/presto/blob/f65d06fa2f9e38e3fc1d79445f56210ed4e126a5/presto-product-tests/src/main/java/com/facebook/presto/tests/jdbc/LdapTests.java ?

One of ideas is to write tempto Fulfiller (take a look at the example: https://github.com/prestodb/presto-yarn/blob/master/presto-yarn-test/src/main/java/com/teradata/presto/yarn/test/fulfillment/SliderClusterFulfiller.java this class provides Slider which is then injected into test here: https://github.com/prestodb/presto-yarn/blob/master/presto-yarn-test/src/main/java/com/teradata/presto/yarn/test/PrestoClusterTest.java).

Using that way, you could setup some entity in your brand new Fulfiller with the usage of injected fields, and that entity could be used in your LDAP test and some other.

How does it sound to you?

kokosing avatar Mar 31 '17 08:03 kokosing

Thanks for the tip! I didn't know this existed. It looks like it can work here, too.

electrum avatar Mar 31 '17 16:03 electrum