maven - fail build when unit test takes too long

后端 未结 6 2125
广开言路
广开言路 2021-02-12 20:22

I have in my project a lot of unit tests, written in JUnit and TestNG. The building process is based on maven with surefire plugin.

Is there any way/plugin for maven to

6条回答
  •  [愿得一人]
    2021-02-12 21:02

    Try to use the junit Ant task with the timeout parameter.

    http://ant.apache.org/manual/Tasks/junit.html

    EDIT:
    Another thing you can do is to use aspectj with someting like that:

    public aspect TestTimeoutChecker {
        long TIMEOUT = 60000;
    
        pointcut invokeEvent() :
            execution(@Test * *(..));
    
        Object around() : invokeEvent() {
    
            long start = System.currentTimeMillis();
            Object object = proceed();
            long took = System.currentTimeMillis() - start;
            if (took > TIMEOUT) {
                throw new RuntimeException("timeout! it took:" + took);
            }
            return object;
        }
    }
    

提交回复
热议问题