当前位置: 首页 > 知识库问答 >
问题:

TestNG tearDown()方法未按预期工作

鲜于光辉
2023-03-14

根据以下文档:http://testng.org/doc/documentation-main.html

“如果测试类上有一个方法tearDown(),那么在每个测试方法之前和之后都会调用它”(JUnit 3)

我使用的是JUnit版本:3.8.1

这里的这个是在我的测试之前运行的,但我希望它会在测试之后。它在测试后没有运行:

@Test(groups = { "all", "inspections" })
public void tearDown() {
    debug.print(thisClass + " ViewAssetInspectionsTest - tearDown invoked.");

    boolean isHomeDisplayed = loggedInPage.isHomeDisplayed();

    if (isHomeDisplayed) {

        boolean clickBackArrow = loggedInPage.goBack();

        Common.reportAssert(driver, thisClass, " click Back Arrow?", clickBackArrow);
    }

    boolean isUnitPropertiesToggleActive = loggedInPage.isUnitPropertiesToggleActive();

    if (isUnitPropertiesToggleActive) {

        boolean clickUnitPropertiesIcon = loggedInPage.clickUnitPropertiesIcon();

        Common.reportAssert(driver, thisClass, " click Unit Properties Icon?", clickUnitPropertiesIcon);
        // System.exit(0);
    }
}

我可以通过将第一行更改为:

@AfterClass
    public void tearDown() {

但是,下一个类(下面)的表示法与第一个类完全相同,但它只能在最后(正确地)运行tearDown()

@Test(groups = { "all", "defects" })
public void tearDown() {

    Common.myPrint(thisClass + " CreateDefectExistingCallerTest tearDown invoked.");

    boolean isDefectDescriptionDisplayed=loggedInPage.isDefectDescriptionDisplayed();

    if(isDefectDescriptionDisplayed) {

        Common.reportAssert(driver, thisClass, " is Defect Description Displayed?", isDefectDescriptionDisplayed);

        boolean clickBackArrow = loggedInPage.goBack();

        Common.reportAssert(driver, thisClass, " click Back Arrow?", clickBackArrow);

        Common.isloadComplete(driver);

        Common.pause(5000);
    }

    boolean isDefectsAssetsDisplayed = loggedInPage.isDefectAssetsDisplayed();

    if (isDefectsAssetsDisplayed) {

        Common.reportAssert(driver, thisClass, " is Defects Assets Displayed?", isDefectsAssetsDisplayed);

        boolean clickBackArrow = loggedInPage.goBack();

        Common.reportAssert(driver, thisClass, " click Back Arrow?", clickBackArrow);

        Common.isloadComplete(driver);

        Common.pause(5000);

    }

    boolean isActivitiesDisplayed = loggedInPage.isactivitiesDisplayed();

    if (isActivitiesDisplayed) {

        boolean clickBackArrow = loggedInPage.goBack();

        Common.reportAssert(driver, thisClass, " click Back Arrow?", clickBackArrow);

        Common.isloadComplete(driver);

        Common.pause(5000);
    }

    boolean isHomeDisplayed=loggedInPage.isHomeDisplayed();

    if(isHomeDisplayed) {

        boolean clickBackArrow = loggedInPage.goBack();

        Common.reportAssert(driver, thisClass, " click Back Arrow?", clickBackArrow);
    }

}

为什么有时会像预期的那样工作,而有时却不是这样?

无论我是作为套件的一部分使用TestNG.xml运行它,还是单独使用Eclipse>run as TestNG测试运行它,都会发生这种情况。

这是testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="tests">
    <parameter name="browser" value="firefox" />
    <parameter name="printToFile" value="false" />
<listeners>
    <listener class-name="listeners.TestNGCustomReportListener" />
</listeners>
<test thread-count="5" name="firefoxTest">

     <groups>
        <define name="all">
            <include name="all" />

         </define>
        <run>
            <include name="all" />
            <exclude name="not-implemented" />

        </run>
    </groups>

    <classes>
        <class name="tests.login.LoginTest" />
        <class name="tests.login.AutoLogOutTest" />
        <class name="tests.login.AutoLogOutWithRestApiTest" />
        <class name="tests.login.ChangePasswordTest" />
        <class name="tests.login.SwitchCustomerProjectsTest" /> 
        <class name="tests.login.ForgotPasswordResetTest" />
        <class name="tests.login.EditUserNameTest" />

        <class name="tests.layers.EnableLayerTest" />
        <class name="tests.layers.EnableLayerStyleTest" />
        <class name="tests.layers.ChangeLayerNameTest" />
        <class name="tests.layers.ChangeStyleNameTest" />
        <class name="tests.layers.ChangeStyleColourTest" />

        <!-- unimplemented tests -->

        <class name="tests.layers.EditStyleIconTest" />
        <class name="tests.layers.CloneStandardLayerTest" />
        <class name="tests.layers.ViewCustomStyleTest" />
        <class name="tests.layers.CreateCustomLayerTest" />
        <class name="tests.layers.AddStyleCustomLayerTest" />
        <class name="tests.layers.EditStyleBuildRuleTest" />
        <class name="tests.layers.EditStyleNameCustomTest" />
        <class name="tests.layers.EditStyleColourCustomTest" />
        <class name="tests.layers.EditStyleIconCustomTest" />
        <class name="tests.layers.BuildCustomLayerTest" />
        <class name="tests.layers.DeleteCustomLayerTest" />
        <class name="tests.layers.CloneCustomLayerTest" />
        <class name="tests.layers.QueryStartsWithTest" />
        <class name="tests.layers.QueryEndsWithTest" />
        <class name="tests.layers.QueryContainsTest" />
        <class name="tests.layers.QueryGreaterThanTest" />
        <class name="tests.layers.QueryLessThanTest" />
        <class name="tests.layers.QueryAddTest" />
        <class name="tests.layers.QuerySubtractTest" />
        <class name="tests.layers.QueryDivideTest" />
        <class name="tests.layers.QueryMultiplyTest" />
        <class name="tests.layers.QueryPowerTest" />
        <class name="tests.layers.QueryRootTest" />
        <class name="tests.layers.QueryLowerTest" />
        <class name="tests.layers.QueryUpperTest" />
        <class name="tests.layers.QueryLengthTest" />
        <class name="tests.layers.QueryRoundTest" />
        <class name="tests.layers.QueryCeilingTest" />
        <class name="tests.layers.QueryFloorTest" /> 

        <class name="tests.networks.SwitchNetworksTest" />
        <class name="tests.networks.ViewNetworkTest" />
        <class name="tests.networks.EditNetworkStyleColourTest" />
        <class name="tests.networks.EditNetworkStyleIconTest" />
        <class name="tests.networks.EditNetworkStyleNameTest" />
        <class name="tests.networks.EditNetworkNameTest" />
        <class name="tests.networks.DeleteNetworkLayerTest" />
        <class name="tests.networks.EditNetworkSectionTest" />
        <class name="tests.networks.EditNetworkGeometryTest" />
        <class name="tests.networks.ViewNetworkHistoryTest" />

        <class name="tests.basemaps.SwitchBasemapsTest" />
        <class name="tests.basemaps.AddWmsLayerTest" />
        <class name="tests.basemaps.DeleteBasemapTest" />

        <class name="tests.jobs.ViewJobsLayerTest" />
        <class name="tests.jobs.CreateNewJobTest" />
        <class name="tests.jobs.CreateGroupJobTest" />
        <class name="tests.jobs.CreateDefectJobTest" />
        <class name="tests.jobs.ViewYourJobsTest" />
        <class name="tests.jobs.ViewAllJobsTest" />
        <class name="tests.jobs.DeleteJobTest" />
        <class name="tests.jobs.ViewJobDetailsTest" />
        <class name="tests.jobs.EditJobDetailsTest" />
        <class name="tests.jobs.EditJobLayerStyleTest" />
        <class name="tests.jobs.AllJobsOnAssetTest" />
        <class name="tests.jobs.ViewJobReportTest" />
        <class name="tests.jobs.OpenJobsReportTest" />
        <class name="tests.jobs.ClosedJobsReportTest" />
        <class name="tests.jobs.MarkJobCompleteTest" />
        <class name="tests.jobs.ShowHideJobGraphTest" />
        <class name="tests.jobs.ViewJobHistoryTest" />
        <class name="tests.jobs.EditJobWorkItemTest" />
        <class name="tests.jobs.DeleteJobWorkItemTest" />

        <class name="tests.inspections.ViewInspectionLayerTest" />
        <class name="tests.inspections.CreateInspectionTest" />
        <class name="tests.inspections.CreateInspectionResourceTemplaterTest" />
        <class name="tests.inspections.CreateInspectionGroupTest" />
        <class name="tests.inspections.CreateInspectionDefectTest" />
        <class name="tests.inspections.ViewInspectionsTest" />
        <class name="tests.inspections.ViewAllInspectionsTest" />
        <class name="tests.inspections.DeleteInspectionTest" />
        <class name="tests.inspections.InspectionDetailsTest" />
        <class name="tests.inspections.EditInspectionTest" />
        <class name="tests.inspections.EditInspectionLayerStyleTest" />
        <class name="tests.inspections.ViewAssetInspectionsTest" />
        <class name="tests.inspections.ViewInspectionReportTest" />
        <class name="tests.inspections.OpenInspectionsReportTest" />
        <class name="tests.inspections.CompletedInspectionsReportTest" />
        <class name="tests.inspections.CompleteInspectionTest" />
        <class name="tests.inspections.InspectionGraphTest" />
        <class name="tests.inspections.InspectionHistoryTest" />

        <class name="tests.defects.ViewDefectsLayerTest" />
        <class name="tests.defects.CreateDefectTest" />
        <class name="tests.defects.CreateDefectNewCallerTest" />
        <class name="tests.defects.CreateDefectExistingCallerTest" />
        <class name="tests.defects.CreateInspectionOnDefectTest" />
        <class name="tests.defects.ViewAllDefectsTest" />
        <class name="tests.defects.DeleteDefectTest" />
        <class name="tests.defects.ViewDefectDetailsTest" />
        <class name="tests.defects.EditDefectDetailsTest" />
        <class name="tests.defects.ViewAssetDefectsTest" />
        <class name="tests.defects.ViewDefectReportTest" />
        <class name="tests.defects.OpenDefectsReportTest" />
        <class name="tests.defects.CompletedDefectsReportTest" />
        <class name="tests.defects.CompleteDefectInspectionTest" />
        <class name="tests.defects.ViewDefectHistoryTest" />

        <class name="tests.projects.ViewProjectsTest" />
        <class name="tests.projects.CreateProjectTest" />
        <class name="tests.projects.AddProjectTaskTest" />
        <class name="tests.projects.RemoveProjectTaskTest" />
        <class name="tests.projects.AddJobExistingProjectTest" />
        <class name="tests.projects.AddJobNewProjectTest" />
        <class name="tests.projects.AddInspectionExistingProjectTest" />
        <class name="tests.projects.AddInspectionNewProjectTest" />
        <class name="tests.projects.AddTasksGroupTest" />
        <class name="tests.projects.RemoveProjectTasksTest" />
        <class name="tests.projects.ViewProjectDetailsTest" />
        <class name="tests.projects.ProjectGraphTest" />
        <class name="tests.projects.ViewAllProjectTasksTest" />
        <class name="tests.projects.EditProjectTest" />
        <class name="tests.projects.DeleteProjectTest" />
        <class name="tests.projects.ViewProjectProgressTest" />
        <class name="tests.projects.ViewProjectReportTest" />
        <class name="tests.projects.ViewProjectTeamsTest" />
        <class name="tests.projects.CloseProjectTest" />
        <class name="tests.projects.ViewProjectAssetsTest" />
        <class name="tests.projects.ChangeTaskProjectTest" />

        <class name="tests.teams.ViewAllTeamsTest" />
        <class name="tests.teams.CreateTeamTest" />
        <class name="tests.teams.AddTeamMemberTest" />
        <class name="tests.teams.RemoveTeamMemberTest" />
        <class name="tests.teams.AddMemberExistingTeamTest" />
        <class name="tests.teams.AddMemberNewTeamTest" />
        <class name="tests.teams.AddGroupExistingTeamTest" />
        <class name="tests.teams.RemoveAllTeamMembersTest" />
        <class name="tests.teams.ViewTeamDetailsTest" />
        <class name="tests.teams.TeamGraphTest" />
        <class name="tests.teams.ViewTeamMembersTest" />
        <class name="tests.teams.EditTeamDetailsTest" />
        <class name="tests.teams.DeleteTeamTest" />
        <class name="tests.teams.TeamReportTest" />
        <class name="tests.teams.ViewTeamProjectsTest" />
        <class name="tests.teams.ViewTeamHistoryTest" />
        <class name="tests.teams.TeamSearchTest" />
        <class name="tests.teams.PromoteTeamMembersTest" />
        <class name="tests.teams.DemoteTeamMembersTest" />

        <class name="tests.routes.ViewRoutesTest" />
        <class name="tests.routes.ViewRouteTest" />
        <class name="tests.routes.ViewRouteDetailsTest" />
        <class name="tests.routes.EditRouteNameTest" />
        <class name="tests.routes.EditRouteColourTest" />
        <class name="tests.routes.ViewRouteOnMapTest" />
        <class name="tests.routes.ViewRouteProjectTest" />
        <class name="tests.routes.ViewRouteHistoryTest" />
        <class name="tests.routes.ViewHistoryEntryTest" />
        <class name="tests.routes.EditHistoryItemTest" />
        <class name="tests.routes.ViewRouteReportTest" />
        <class name="tests.routes.ViewRouteWaypointsTest" />
        <class name="tests.routes.AddStartPoint1Test" />
        <class name="tests.routes.AddStartPoint2Test" />
        <class name="tests.routes.RemoveStartPointTest" />
        <class name="tests.routes.AddEndPoint1Test" />
        <class name="tests.routes.AddEndPoint2Test" />
        <class name="tests.routes.RemoveEndpointTest" />
        <class name="tests.routes.AddWayPointTest" />
        <class name="tests.routes.RemoveWayPointTest" />
        <class name="tests.routes.ChangeWayPointOrderTest" />
        <class name="tests.routes.OptimizeRouteTest" />
        <class name="tests.routes.CreateRouteTest" />
        <class name="tests.routes.CreateRouteAddStartTest" />
        <class name="tests.routes.CreateRouteRemoveStartTest" />
        <class name="tests.routes.CreateRouteRemoveTaskTest" />
        <class name="tests.routes.CreateRouteAddTaskTest" />

        <class name="tests.search.SearchByItemIdTest" />
        <class name="tests.search.SearchAttributeValueTest" />
        <class name="tests.search.SearchCollectionsTest" />
        <class name="tests.search.SearchDesignsTest" />
        <class name="tests.search.SearchFilesTest" />
        <class name="tests.search.SearchFoldersTest" />
        <class name="tests.search.SearchGroupsTest" />
        <class name="tests.search.SearchIdsTest" />
        <class name="tests.search.SearchImportsTest" />
        <class name="tests.search.SearchInspectionsTest" />
        <class name="tests.search.SearchLocationsTest" />
        <class name="tests.search.SearchReportsTest" />
        <class name="tests.search.SearchSchedulesTest" />
        <class name="tests.search.SearchUsersTest" />
        <class name="tests.search.SearchWorkflowsTest" />
        <class name="tests.search.SearchRoutesTest" />
        <class name="tests.search.SearchProjectsTest" />
        <class name="tests.search.SearchTeamsTest" />
        <class name="tests.search.SearchDesignNameTest" />

        <class name="tests.schedules.ViewAllSchedulesTest" />
        <class name="tests.schedules.ViewCalendarScheduleDetailsTest" />
        <class name="tests.schedules.ViewCalendarScheduleDatesTest" />
        <class name="tests.schedules.CyclicScheduleDetailsTest" />
        <class name="tests.schedules.CyclicScheduleDatesTest" />
        <class name="tests.schedules.EditScheduleDetailsTest" />
        <class name="tests.schedules.EditCyclicScheduleDatesTest" />
        <class name="tests.schedules.DeleteScheduleTest" />
        <class name="tests.schedules.ViewScheduleHistoryTest" />
        <class name="tests.schedules.ViewScheduleReportTest" />
        <class name="tests.schedules.JobCalendarScheduleTest" />
        <class name="tests.schedules.InspectionCalendarScheduleTest" />
        <class name="tests.schedules.ProjectCalendarScheduleTest" />
        <class name="tests.schedules.JobCyclicScheduleTest" />
        <class name="tests.schedules.InspectionCyclicScheduleTest" />
        <class name="tests.schedules.ProjectCyclicScheduleTest" />

        <class name="tests.gateway.ViewAllFilesTest" />
        <class name="tests.gateway.ViewAllFoldersTest" />
        <class name="tests.gateway.ViewAllImportsTest" />
        <class name="tests.gateway.UploadFileTest" />
        <class name="tests.gateway.DragAndDropFileTest" />
        <class name="tests.gateway.ImportCentrelineNetworkTest" />
        <class name="tests.gateway.ImportNsgNetworkTest" />
        <class name="tests.gateway.ImportGeometryNetworkTest" />
        <class name="tests.gateway.ViewFileDetailsTest" />
        <class name="tests.gateway.DeleteFileTest" />
        <class name="tests.gateway.ViewFolderDetailsTest" />
        <class name="tests.gateway.DeleteFolderTest" />
        <class name="tests.gateway.ViewImportDetailsTest" />
        <class name="tests.gateway.DeleteImportTest" />

        <class name="tests.permissions.ViewAllUsersTest" />
        <class name="tests.permissions.ViewAllUserGroupsTest" />
        <class name="tests.permissions.ViewUserDetailsTest" />
        <class name="tests.permissions.ViewUsersGroupsTest" />
        <class name="tests.permissions.ViewUsersModulesTest" />
        <class name="tests.permissions.ViewAccessAdvisorTest" />
        <class name="tests.permissions.EditUserDetailsTest" />
        <class name="tests.permissions.ArchiveUserTest" />
        <class name="tests.permissions.ViewUserHistoryTest" />
        <class name="tests.permissions.ViewUserReportTest" />
        <class name="tests.permissions.AddUserToGroupTest" />
        <class name="tests.permissions.RemoveUserFromGroupsTest" />
        <class name="tests.permissions.AddModuleToUserTest" />
        <class name="tests.permissions.RemoveModulesFromUserTest" />
        <class name="tests.permissions.ViewGroupDetailsTest" />
        <class name="tests.permissions.ViewUsersInGroupTest" />
        <class name="tests.permissions.ViewGroupPermissionsTest" />
        <class name="tests.permissions.EditGroupDetailsTest" />
        <class name="tests.permissions.EditUsersInGroupTest" />
        <class name="tests.permissions.RemoveUsersFromGroupTest" />
        <class name="tests.permissions.ArchiveGroupTest" />
        <class name="tests.permissions.DeleteGroupTest" />
        <class name="tests.permissions.EditGroupPermissionsTest" />
        <class name="tests.permissions.AddAttributesReadTest" />
        <class name="tests.permissions.AddAttributesWriteTest" />
        <class name="tests.permissions.RemoveAttributesTest" />
        <class name="tests.permissions.MakeDesignsReadTest" />
        <class name="tests.permissions.MakeDesignsWriteTest" />
        <class name="tests.permissions.ViewGroupReportTest" />
        <class name="tests.permissions.ChangeTeamUserTest" />

        <class name="tests.mesh.ViewLightSensorTest" />
        <class name="tests.mesh.ViewLampSensorDetailsTest" />
        <class name="tests.mesh.TurnOnLampTest" />
        <class name="tests.mesh.TurnOffLampTest" />

        <class name="tests.designer.ViewAllDesignsTest" />
        <class name="tests.designer.ViewDesignDetailTest" />
        <class name="tests.designer.ViewAssetDesignGraphTest" />
        <class name="tests.designer.ViewDesignAttributesTest" />
        <class name="tests.designer.EditDesignNameTest" />
        <class name="tests.designer.EditDesignIconTest" />
        <class name="tests.designer.EditDesignColourTest" />
        <class name="tests.designer.EditDesignAttributesTest" />
        <class name="tests.designer.EditDesignPropertiesTest" />
        <class name="tests.designer.RemoveDesignAttributesTest" />
        <class name="tests.designer.ViewDesignInspectionQuestionsTest" />
        <class name="tests.designer.EditDesignInspectionQuestionsTest" />
        <class name="tests.designer.ViewInspectionDesignGraphTest" />
        <class name="tests.designer.RemoveInspectionQuestionsTest" />
        <class name="tests.designer.EditInspectionAssetsTest" />
        <class name="tests.designer.CreateAssetDesignTest" />
        <class name="tests.designer.CreateNetworkDesignTest" />
        <class name="tests.designer.CreateInspectionDesignTest" />
        <class name="tests.designer.CreateDefectDesignTest" />
        <class name="tests.designer.CreateSystemDataDesignTest" />
        <class name="tests.designer.AttemptDeleteDesignTest" />
        <class name="tests.designer.DeleteInspectionDesignTest" />
        <class name="tests.designer.DeleteDesignTest" />
        <class name="tests.designer.AddAttributesNewAssetTest" />
        <class name="tests.designer.CreateItemNewAssetTest" />

        <class name="tests.workflow.ViewAllWorkflowsTest" />
        <class name="tests.workflow.ViewWorkflowDetailsTest" />
        <class name="tests.workflow.EditWorkflowDetailsTest" />
        <class name="tests.workflow.AddWorkflowCheckTest" />
        <class name="tests.workflow.DeleteWorkflowCheckTest" />
        <class name="tests.workflow.DeleteAllWorkflowsCheckTest" />
        <class name="tests.workflow.WorkflowAddEmailTest" />
        <class name="tests.workflow.WorkflowEditResourceTest" />
        <class name="tests.workflow.WorkflowDeleteResourceTest" />
        <class name="tests.workflow.WorkflowCallUrlTest" />
        <class name="tests.workflow.WorkflowSendEmailTest" />
        <class name="tests.workflow.TriggerEditResourceTest" />
        <class name="tests.workflow.TriggerDeleteResourceTest" />
        <class name="tests.workflow.TriggerSendUrlCallTest" />
        <class name="tests.workflow.DeleteWorkflowActionTest" />
        <class name="tests.workflow.DeleteAllWorkflowActionsTest" />
        <class name="tests.workflow.CreateNewWorkflowTest" />
        <class name="tests.workflow.DisableWorkflowTest" />
        <class name="tests.workflow.EnableWorkflowTest" />
        <class name="tests.workflow.DeleteWorkflowTest" />
        <class name="tests.workflow.CreateCheckWithErrorsTest" />
        <class name="tests.workflow.EditCheckTest" />
        <class name="tests.workflow.ManageWorkflowAttributesTest" />

        <class name="tests.reports.ViewAllReportsTest" />
        <class name="tests.reports.ViewReportsDetailsTest" />
        <class name="tests.reports.ViewPreviousReportsTest" />
        <class name="tests.reports.GenerateNewReportTest" />
        <class name="tests.reports.DeleteReportTest" />

        <class name="tests.streetlighting.ViewStreetlightsLayerTest" />
        <class name="tests.streetlighting.ViewStreetlightsNightscapeTest" />
        <class name="tests.streetlighting.PlaceNewUnitWithMapTest" />
        <class name="tests.streetlighting.PlaceNewUnitManuallyTest" />
        <class name="tests.streetlighting.CreateUnitWithoutIdTest" />
        <class name="tests.streetlighting.CreateUnitWithoutCoordsTest" />
        <class name="tests.streetlighting.CancelCreatingUnitTest" />
        <class name="tests.streetlighting.ViewStreetlightsDetailsTest" />
        <class name="tests.streetlighting.EditStreetlightsDetailsTest" />
        <class name="tests.streetlighting.AddStreetlightComponentTest" />
        <class name="tests.streetlighting.RemoveStreetlightComponentTest" />
        <class name="tests.streetlighting.ViewStreetlightComponentDetailsTest" />
        <class name="tests.streetlighting.EditStreetlightGeometryTest" />
        <class name="tests.streetlighting.ViewStreetlightComponentGraphTest" />

        <class name="tests.collections.ViewAllCollectionsTest" />
        <class name="tests.collections.ViewCollectionDetailsTest" />
        <class name="tests.collections.ViewCollectionItemsTest" />
        <class name="tests.collections.ViewCollectionHistoryTest" />
        <class name="tests.collections.AddItemToCollectionTest" />
        <class name="tests.collections.AddGeometryItemToCollectionTest" />
        <class name="tests.collections.ViewCollectionItemDetailsTest" />
        <class name="tests.collections.EditCollectionItemDetailsTest" />
        <class name="tests.collections.EditCollectionItemGeometryTest" />
        <class name="tests.collections.DeleteCollectionItemTest" />
        <class name="tests.collections.ViewCollectionReportTest" />
        <class name="tests.collections.ViewItemReportTest" />
        <class name="tests.collections.CreateNewCollectionTest" />
        <class name="tests.collections.DeleteCollectionTest" />

    </classes>
</test>
</suite> 

最终编辑:

我决定使用@after class方法运行,因为它更加一致:

@AfterClass
public void tearDown() {

共有1个答案

吴宝
2023-03-14

如果您真的希望使用testng执行junit测试,请注意doc中属性的更改:

TestNG可以运行JUnit3和JUnit4测试。您所需要做的就是将JUnit jar文件放在类路径上,在TestNg.ClassNames属性中指定JUnit测试类,并将TestNg.JUnit属性设置为true:

<test name="Test1" junit="true">

然后注意JUnit的tearDown方法应该被重写,如下所示:

@Override
protected void tearDown()
                 throws java.lang.Exception 
 类似资料:
  • 我能够在iothub消息(从云到设备的消息)上打开一个侦听器,但我无法订阅direct方法。我尝试使用mqtt支持,而不是iothub库 我已经跟踪https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-direct-methods#mqtt但一定有一个小细节我还没有设法做到正确 这是我的代码(python)

  • 我正在使用spring Roo并希望访问Controller类中的一个bean,该类在ApplicationContext.xml中具有以下配置: 配置类本身是: 在我的Controller中,我认为一个简单的Autowired注释应该可以完成这项工作 在启动过程中,spring在setSkipWeeks方法中打印消息。不幸的是,每当我在控制器中调用config.getSkipWeeks()时,它

  • 当我运行以下程序时,它只打印 然而,从Java 8的equalsIgnoreCase文档中我们发现: 如果以下至少一项为真,则两个字符c1和c2被视为相同的忽略情况: •对每个字符应用java.lang.character.ToUpperCase(char)方法会产生相同的结果 所以我的问题是为什么这个程序不打印 在这两种操作中,都使用了大写字符。

  • 我试图使用来传输我根据前面的问题设置的自定义标头。 我在文件中读到... 我的属性包括:

  • 我正在和selenium一起工作,刮一些数据。 有一个按钮在页面上,我正在点击说“Custom_Cols”。这个按钮为我打开了一个窗口,我可以在那里选择我的列。 我的问题是为什么新窗口上的元素不可见,即使我正在等待元素的可见。补充一下,我已经尝试增加延迟时间,但我还是会偶尔出现这个错误。 我的密码在这里