forked from springside/springside4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test case严格按方法名排序执行,并在console里打印测试进度。
- Loading branch information
1 parent
13555de
commit 4b7a491
Showing
3 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...boot-api/src/test/java/org/springside/examples/bootapi/functional/BaseFunctionalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.springside.examples.bootapi.functional; | ||
|
||
import org.junit.Rule; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.boot.test.WebIntegrationTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springside.examples.bootapi.BootApiApplication; | ||
import org.springside.modules.test.rule.TestProgress; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = BootApiApplication.class) | ||
// 定义为Web集成测试,并使用随机端口号 | ||
@WebIntegrationTest("server.port=0") | ||
// 定义每执行完一个Test文件刷新一次Spring Application Context,避免Case间的数据影响. | ||
// 但Test文件内多个测试方法间的影响仍需注意 | ||
@DirtiesContext | ||
public abstract class BaseFunctionalTest { | ||
|
||
// 注入启动server后的实际端口号 | ||
@Value("${local.server.port}") | ||
protected int port; | ||
|
||
// 在Console里打印Case的开始与结束,更容易分清Console里的日志归属于哪个Case. | ||
@Rule | ||
public TestRule testProgress = new TestProgress(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
modules/utils/src/test/java/org/springside/modules/test/rule/TestProgress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.springside.modules.test.rule; | ||
|
||
import org.junit.rules.TestWatcher; | ||
import org.junit.runner.Description; | ||
|
||
/** | ||
* 在Console里打印Case的开始与结束,更容易分清Console里的日志归属于哪个Case. | ||
* | ||
* @author calvin | ||
*/ | ||
public class TestProgress extends TestWatcher { | ||
|
||
@Override | ||
protected void starting(Description description) { | ||
System.out.println("\n[Test Case starting] " + description.getTestClass().getSimpleName() + "." | ||
+ description.getMethodName() + "()\n"); | ||
} | ||
|
||
@Override | ||
protected void finished(Description description) { | ||
System.out.println("\n[Test Case finished] " + description.getTestClass().getSimpleName() + "." | ||
+ description.getMethodName() + "()\n"); | ||
} | ||
|
||
} |