Debugging Maven test cases with Eclipse 如何在Eclipse中為Maven的test case除錯
1. Add Junit 4.7.1 dependency in project's pom files.
首先, 先加入Junit 4.7.1.
junit
junit
4.8.1
test
2. write a test case in Junit 4.7, like below:
寫一個Junit 4.7的測試用例. 例如:
package com.sml.form.restore;
import org.junit.Assert;
import org.junit.Test;
import com.sml.formrestore.SpringContextUtil;
import com.sml.formrestore.mvc.dao.product.mapper.ProductSpecMapper;
import com.sml.formrestore.mvc.dao.product.model.ProductSpec;
public class StartUpTest {
@Test
public void TestStartUpTestCase(){
// the test method must be annotated with @Test, and starts with Test, or ends with Test, TestCase
// 用例名稱必需以Test開首,或以Test, 或TestCase結尾,
// Write your test case here...
//在這裏寫測試用例...
}
}
3. Finally, if you want to use Eclipse debugger to debug, you must:
最後, 如果你想以Eclipse內置的除錯工具除錯, 你需要:
a. Right-click project -> Debug As->Debug Configuration
b. Input "-Dmaven.surefile.debug test" in Goals
c. Add a parameter "forkMode" with value "never"
甲. 右按項目-> Debug As->Debug Configuration
乙. 於Goals輸入"-Dmaven.surefile.debug test"
丙. 加一個參數, 名稱:"forkMode", 值:"never".
參見:ref:http://stackoverflow.com/questions/12598261/maven-build-debug-in-eclipse
Moreover:
另外:
I have tested with the parameter forkCount=0 described here, but not working.
測試過參數forkCount=0, 但跑不了.
http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html
package com.sml.form.restore;
import org.junit.Assert;
import org.junit.Test;
import com.sml.formrestore.SpringContextUtil;
import com.sml.formrestore.mvc.dao.product.mapper.ProductSpecMapper;
import com.sml.formrestore.mvc.dao.product.model.ProductSpec;
public class StartUpTest {
@Test
public void TestStartUpTestCase(){
// the test method must be annotated with @Test, and starts with Test, or ends with Test, TestCase
// 用例名稱必需以Test開首,或以Test, 或TestCase結尾,
// Write your test case here...
//在這裏寫測試用例...
}
}
3. Finally, if you want to use Eclipse debugger to debug, you must:
最後, 如果你想以Eclipse內置的除錯工具除錯, 你需要:
a. Right-click project -> Debug As->Debug Configuration
b. Input "-Dmaven.surefile.debug test" in Goals
c. Add a parameter "forkMode" with value "never"
甲. 右按項目-> Debug As->Debug Configuration
乙. 於Goals輸入"-Dmaven.surefile.debug test"
丙. 加一個參數, 名稱:"forkMode", 值:"never".
參見:ref:http://stackoverflow.com/questions/12598261/maven-build-debug-in-eclipse
Moreover:
另外:
I have tested with the parameter forkCount=0 described here, but not working.
測試過參數forkCount=0, 但跑不了.
http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html
Comments