TestNG - 仅在定义了6个或更多测试时才例外

时间:2011-11-04 12:12:13

标签: spring unit-testing testing testng

以下代码失败,但仅在定义了6个或更多测试时才会失败。也就是说,无论我有什么测试。我已尝试进行5次重复测试,这些测试全部通过,然后添加另一个以查看下面的断言失败。 有没有人知道发生了什么?

我使用Spring Data Graph运行带有Neo4J数据库的Spring MVC,TestNG Version 5.8。

@ContextConfiguration(locations = {"classpath:application-context-test.xml"})
public class EntityTest extends AbstractTestNGSpringContextTests {

    @Autowired
    private GraphDatabaseContext graphDatabaseContext;

    @BeforeClass
    protected void setUp() throws Exception {
        Assert.assertNotNull(graphDatabaseContext);
    }

    @Test(groups = {"functest"})
    public void testEmployeeCreation() throws Exception {
       //please note that these methods are _literally_ empty.
    }

    @Test(groups = {"functest"})
    public void test2EmployeeCreation() throws Exception {
    }
    @Test(groups = {"functest"})
    public void test3EmployeeCreation() throws Exception {
    }
    @Test(groups = {"functest"})
    public void test4EmployeeCreation() throws Exception {
    }
    @Test(groups = {"functest"})
    public void test5EmployeeCreation() throws Exception {
    }

    @Test(groups = {"functest"})
    public void test6EmployeeCreation() throws Exception {
    }
}

的testng.xml:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Maven Tests" verbose="1" annotations="JDK">

    <parameter name="echo.timeout" value="60000"/>

    <test name="Functional and Check-in Tests">

        <groups>
            <run>
                <include name="functest"/>
                <include name="checkintest"/>
            </run>
        </groups>

        <classes>
            <class name="com.noname.entity.EntityTest"/>
        </classes>

    </test>

</suite>

TESTLOG:

 java.lang.AssertionError: 
Expected :true
Actual   :false

    at org.testng.Assert.fail(Assert.java:84)
    at org.testng.Assert.failNotEquals(Assert.java:438)
    at org.testng.Assert.assertTrue(Assert.java:32)
    at org.testng.Assert.assertNotNull(Assert.java:352)
    at org.testng.Assert.assertNotNull(Assert.java:342)
    at com.noname.entity.EntityTest.setUp(EntityTest.java:25)

1 个答案:

答案 0 :(得分:0)

当你遇到这样的问题时,你首先想到的是某些资源是否被用尽(例如数据库连接或打开文件)。检查删除graphDatabaseContext是否有所作为。不可否认,在查看GraphDatabaseContextAbstractTestNGSpringContextTests的api时,我没有看到任何明显需要发布的引用案例,但也许更熟悉这些类的人可以从那里获取它。