[英]How to know which top container is currently “focused” according to the focused controls?
[英]How to know which test is currently triggered
我有下一个代码
class Test extend Parent{
@Test
public void testMethod(){
};
}
class Parent {
'here I need to have some check which test is running now'
}
至于在Test类之前初始化Parent类,如何知道当前正在运行哪个jUnit测试,或者如果有多个子类,则如何知道哪个子类呢?
您可以通过以下方式获取启动父类创建的后代类的名称 :
// in the constructor of the parent System.out.println(Thread.currentThread().getStackTrace()[2].getClassName());
在多重继承级别的情况下,您可以编写一些额外的自定义逻辑并遍历当前的堆栈跟踪。
免责声明:您要做的事情看起来并不好。 使用内置的功能,如@Before
, @BeforeClass
或一些重构可能是一个更好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.