Google software development visible from testing and Google Testing Blog According to (: //testing.googleblog.com/2010/12/test-sizes.html), Google unifies the test categories of developers (until then, system test, EtoE test, UI test, Selenium test, etc. Since there are expressions and none of them clearly define what kind of test they are), we introduced the concept of TestSize and defined each as follows.
S(Small)test | M(Medium)test | L(Large)test | E(Enormous)test | |
---|---|---|---|---|
Temporal goal (for each method) | Run in less than 100ms | Run in less than 1s | Run as fast as possible | Run as fast as possible |
Maximum execution time | Forcibly terminate the S test target 1 minute after startup | Forced termination of M test target 5 minutes after startup | Forcibly terminate the L test target 15 minutes after startup | Forcibly terminate the E test target 1 hour after startup |
S test | M test | L test | E test | |
---|---|---|---|---|
Network service (socket open) | mock | localhost only | ○ | ○ |
Database | mock | ○ | ○ | ○ |
File system access | mock | ○ | ○ | ○ |
Access to the system facing the user | mock | Not recommended | ○ | ○ |
System call execution | × | Not recommended | ○ | ○ |
Multithread | Not recommended | ○ | ○ | ○ |
sleep statement | × | ○ | ○ | ○ |
System properties | × | ○ | ○ | ○ |
By defining the test execution timing for each TestSize, it is possible to execute the required number of tests in the required phase and provide quick feedback to the user.
For example, following Cookpad article, the execution timing can be divided as follows. By doing so, Cookpad can execute the test by pull request within 5 minutes and give feedback to the user at an early stage.
S test | M test | L test | E test | |
---|---|---|---|---|
Execution timing | For each pull request | Every pull request or every time it is merged into Master | Optional or per release | Optional or per release |
So how do you split TestSize and its execution timing? Here, the case of using Java and Maven will be explained.
Annotation called Category has been added to JUnit, which is a typical Java test framework, from JUnit 4.8.
By marking the method or class to be tested with @Category
, you can have fine control over what is executed from the test suite.
For details, please refer to this article.
Define an interface for each TestSize,
You can control the test execution target by passing the defined interface to the argument of @Category
.
package hogehoge;
public interface Small {}
package hogehoge;
public interface Medium {}
public class hoge {
@Category(Small.class)
@Test
public void a() {
fail();
}
@Category(Medium.class)
@Test
public void b() {
fail();
}
}
If you can pass TestSize as a parameter when executing Maven, it is possible to divide the execution timing by TestSize.
If possible, it would be nice to be able to do this. If TestSize is not specified, all tests can be executed and one or more TestSizes can be specified. In that case, the specified TestSize test is executed.
mvn test // All tests run.
mvn test -P Small // Small tests run.
mvn test -P Small,Medium // Small and medium tests run.
Maven settings to achieve the above are as follows.
Specify TestSize in groups
of maven-surefire-plugin
.
By default, empty is specified so that all tests are executed when no argument is specified.
<project ...>
<properties>
<testcase.groups></testcase.groups>
</properties>
<profiles>
<profile>
<id>Small</id>
<properties>
<testcase.groups>hogehoge.Small</testcase.groups>
</properties>
</profile>
<profile>
<id>Medium</id>
<properties>
<testcase.groups>hogehoge.Medium</testcase.groups>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
<groups>${testcase.groups}</groups>
</configuration>
</plugin>
</plugins>
</build>
</project>
Google, Cookpad often wrote about TestSize, but I did not have an article that describes how to realize it, so I wrote it. I am honored to be of any help.
Recommended Posts