2

I am using Junit framework and writing parameterized testing. I have a base abstract class which is extended by multiple test case classes.

Is there a way to find out the test case class name from the static code of the base abstract class. Any dirty hacks are welcome.

I tried the stackTrace but cause the static code of the base abstract class loads first, the stackTrace has no idea about the class that is extending this abstract class.

Thanks in advance.

  • any reason why your method in abstract class is static ? – sanbhat Apr 23 '14 at 07:03
  • 1
    I think that you need an instance method instead of a static one. The static method belongs to the parent class. If the method was not static `this.getClass().getName()` would have done the job – Totò Apr 23 '14 at 07:23
  • If you are using junit4 you may want to have a look at `@Before` – Totò Apr 23 '14 at 07:26
  • maybe this can help:http://stackoverflow.com/questions/6901764/get-concrete-class-name-from-abstract-class – ZaoTaoBao Apr 23 '14 at 08:02
  • The reason behind the method being static is, its the method that gets the parameters for the testing. I need to have the set of parameters well before the test even starts.. Hence I have to make it static. If it wasn't static, I could have use the stackTrace hack to get the things to work. – user3563327 Apr 23 '14 at 09:00
  • and `@Before` helps me to do something before `@Test` but the place where I want the testcase class name is `@Parameters`. – user3563327 Apr 23 '14 at 09:35
  • "Is there a way to find out the test case class name" why does the code *care* what its class name is? – Raedwald Apr 24 '14 at 11:47

0 Answers0