About TestSize advocated by Google and how to realize TestSize by Java and Maven

What is Test Size?

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 ×

Division of execution timing by TestSize

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

Realization of TestSize by Java and Maven

So how do you split TestSize and its execution timing? Here, the case of using Java and Maven will be explained.

environment

Category class and annotation

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();
    }
}

How to specify TestSize by Maven

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>

Summary

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

About TestSize advocated by Google and how to realize TestSize by Java and Maven
[Java] How to output and write files!
[Java] [Maven3] Summary of how to use Maven3
[Java] How to use FileReader class and BufferedReader class
[Java] How to get and output standard input
How to get and study java SE8 Gold
How to access Java Private methods and fields
[Java] How to use Calendar class and Date class
[Java] Types of comments and how to write them
A memo about the types of Java O/R mappers and how to select them
[Java] How to get the key and value stored in Map by iterative processing
Java memory management and how to read GC Viewer
[Java] How to get a request by HTTP communication
[Java] How to cut out a character string character by character
How to convert A to a and a to A using AND and OR in Java
How to boot by environment with Spring Boot of Maven
Introduction to Effective java by practicing and learning (Builder pattern)
Difference between Java and JavaScript (how to find the average)
What happened in "Java 8 to Java 11" and how to build an environment
How to call and use API in Java (Spring Boot)
How to write and notes when migrating from VB to JAVA
How to develop and register a Sota app in Java
Think about how to divide MVC into M and V
Differences in how to handle strings between Java and Perl
A story about misunderstanding how to use java scanner (memo)
How to lower java version
[Java] How to use Map
Java --How to make JTable
How to use java Optional
How to minimize Java images
How to write java comments
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] How to use string.format
[Java] About String and StringBuilder
How to use Java Map
How to set Java constants
How to use Java variables
About Java Packages and imports
How to convert Java radix
[Java] How to implement multithreading
[Java] How to use Optional ①
How to initialize Java array
Basics of Java development ~ How to write programs (variables and types) ~
[Java] How to use static modifiers (What are static final and static import)
How to manage Java code automatically generated by jOOQ & Flyway sample
[Java] How to convert from String to Path type and get the path
How to encrypt and decrypt with RSA public key in Java
About Java static and non-static methods
How about TECH ACADEMY ?? [Java course]
How to use EventBus3 and ThreadMode
Studying Java # 6 (How to write blocks)
[Introduction to Java] About lambda expressions
About fastqc of Biocontainers and Java
[Introduction to Java] About Stream API
[Java] How to update Java on Windows
How to make a Java container
[Java beginner] About abstraction and interface
How to disassemble Java class files