Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the script structure of groovy in nGrinder

Shulou Source: shulou.com Published: 2022-06-02 02:55:36 09月14日 Update

This article analyzes "what is the script structure of groovy in nGrinder". The content is detailed and easy to understand. Friends who are interested in "what is the script structure of groovy in nGrinder" can follow the editor's train of thought to read it in depth. I hope it will be helpful to you after reading. Follow the editor to learn more about "what is the script structure of groovy in nGrinder".

The structure of the groovy script in ngrinder is similar to junit, while encapsulating its own annotations on the basis of junit to control the execution of the script.

1. The running logic diagram is as follows:

Only the logic of the groovy script is listed here, and the jython script is similar and will not be covered separately here.

II. Comparison of the use of various notes

III. Focus

In ngrinder, using single-process multithreading is usually sufficient for most tests, so:

What we need to pay attention to most is @ Test, which is the body of the loop.

The second is @ Before, where shared variables for multiple loop bodies are set.

Next are @ BeforeThread and @ AfterThread, which are used to set the behavior of each thread before and after execution.

IV. Specific code structure

@ RunWith (GrinderRunner) / / add this annotation to every test class

Class TestRunner {

@ BeforeProcess / / execute before each process starts

Public static void beforeProcess () {

/ / load resource files, initialize GTest, etc.

}

@ BeforeThread / / execute before each thread executes

Public void beforeThread () {

/ / Log in, set cookie and so on

}

@ Before / / execute before each @ Test annotated method is executed

Public void before () {

/ / set variables, logic shared by multiple @ Test methods, etc.

}

@ Test / / keep running until the test ends. The methods of each @ Test annotation are executed asynchronously.

Public void foo () {

/ /...

}

@ Test

Public void bar () {

/ /...

}

@ After / / execute after each @ Test annotated method is executed

Public void after () {

/ / rarely used

}

@ AfterThread

Public void afterThread () {

/ / logging out and so on

}

@ AfterProcess / / execute after the end of each process

Public static void afterProcess () {

/ / close resources

}

So much for sharing what is the script structure of groovy in nGrinder. I hope the above content can improve everyone. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

Tags: Script structure annotation method thread process logic test run content variable multiple loop body knowledge resource follow learning loop continuous code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn Apple Redmi MariaDB