使用maven进行测试设置断点调试的方法

在Maven中配置测试插件surefire来进行单元测试,默认情况下,surefire会执行文件名以Test开头或结尾的测试用例,或者是以TestCase结尾的测试用例。
               <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>${surefireArgLine}</argLine>
                    <!--testng.xml -->
                    <suiteXmlFiles>
                        <suiteXmlFile>target/test-classes/testcase/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <testFailureIgnore>true</testFailureIgnore>
<!--                     <debugForkedProcess>true</debugForkedProcess>  -->
                    <properties>
                        <property>
                            <name>usedefaultlisteners</name>
                            <value>false</value>
                        </property>
                    </properties>
                    <!--  target -->
                    <workingDirectory>target/</workingDirectory>
                </configuration>
            </plugin>  
按上述配置执行,maven test 会忽略程序中的断点执行,如果要进行调试可通过下面两个方法设置:
1、使用配置testFailureIgnore 配置
在pom.xml文件中<configuration> 结点下,增加<debugForkedProcess>true</debugForkedProcess>
2、配置maven test参数
在Debug->Debug Config 设置框中,设置Goals值为:test -Dmaven.surefire.debug即可。


注意:在配置支持断点调试的模式下运行后,控制台console会出现“Listening for transport dt_socket at address: 5005”,要单击一下才能继续运行。









原文地址:https://www.cnblogs.com/doit8791/p/5766239.html