我想获得当前正在执行的测试方法,@Before以便我可以在当前正在执行的方法上应用注释.
public class TestCaseExample {
@Before
public void setUp() {
// get current method here.
}
@Test
@MyAnnotation("id")
public void someTest {
// code
}
}
Run Code Online (Sandbox Code Playgroud) 我想在@Before方法中获取当前正在执行的TestCase方法的名称.例
public class SampleTest()
{
@Before
public void setUp()
{
//get name of method here
}
@Test
public void exampleTest()
{
//Some code here.
}
}
Run Code Online (Sandbox Code Playgroud) 当我为spring应用程序运行测试用例(Junit)时,我得到了这个错误。
我搜索了此问题,并且得到了这样的信息:每当发生惰性初始化,并且我的应用程序尝试在会话关闭(对象分离)时尝试获取第二级数据,那么就会发生此错误,我们无法将初始化作为EAGER作为其性能问题。
我的测试课程包括:
@RunWith(SpringJUnit4ClassRunner.class)
public class MyTestClass extends AbstractControllerTest {
@Rule
public TestName testMethodName = new TestName();
@Before
public void setUp() throws Exception
{
super.setUp();
}
@After
public void tearDown() throws Exception
{
super.tearDown();
}
@Test
public void myTestMethod ()
{
assertTrue("Response Validating",validate(baseEntity,perform()));
}
}
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以使方法assertTrue(“ Response Validating”,validate(baseEntity,perform())); 事务中的绑定可以与当前会话或新会话绑定,以便我的分离对象成为持久对象,然后我的应用程序也可以获取第二级数据。我搜索了此问题,并在以下链接上找到了解决方案:http : //www.jroller.com/RickHigh/entry/hibernate_spring_simulating_an_opensessioninviewfilter, 但此链接无法满足我的要求,因为它需要在其上创建事务的目标对象。