TESTNG provides several interfaces for listeners and interceptors for our own development, by implementing these interfaces to define the behavior we want in testing
Interface list:
- Iannotationtransformer (Doc,javadoc)
- IAnnotationTransformer2 (Doc,javadoc)
- ihookable (Doc,javadoc)
- Iinvokedmethodlistener (Doc, Javadoc)
- Imethodinterceptor (Doc,javadoc)
- ireporter (Doc,javadoc)
- Isuitelistener (Doc, Javadoc)
- Itestlistener (Doc,javadoc)
TESTNG provides three ways to configure the developer's own interface:
1. Annotations
A class-level annotation is provided in testng, @Listeners ({*.class, *.class})
*.class is our own implementation of the monitoring
This method is more commonly used in our development.
2. Configuration files
In the configuration file we can
<listeners>
<listener class-name= "full class name" ></listener>
</listeners>
For plug-and-pull configuration, this is more flexible and more convenient than the first type of writing to die in code
3. By way of Serviceloader
This approach is more complex, and it's more used in writing extended frameworks, such as our enhancements to testng, and then encapsulating them into frameworks that are available to others
When it comes to packing, you have to say something. Meta-inf, in fact, we often see this in engineering documents, but it seems that some people do not know its role,
Before I studied the testng function, I was part of this.
Let's start with Meta-inf.
It contains the following files/folders
1.MANIFEST. MF-----Define some extensions and packaging-related data
2.INDEX. LIST------This file is generated when the Jar tool is packaged with the '-I ' option, which contains the location declaration in the application or extension package, which is part of the Jarindex implementation and is typically used by the ClassLoader to speed up the loading process of the class
3.X.SF------The signature file for the jar file
4.X.DSA------The signature block file, which is associated with the signature file with the same file name, which stores the signature digest and the signature file.
5.services/------This directory is used to store configuration files for all business supply sources
These files or folders can be automatically identified and interpreted by the Java 2 platform and configured into applications, extensions, ClassLoader, and business
The next thing we do is to put our written interface extension implementation Class (. Class), and Meta-inf in the same directory, remember that if the class with the package name, then the Meta-inf sibling is the root directory of the package
Then we create a Services folder in Meta-inf, where we create a file with the name of the interface we implement, and the contents of the file are the full directory of our implementation class.
Package Meta-inf and class files to generate a jar file
This is done, and we just need to add the generated jar package to the project.
Note: If we operate in the IDE, then we need to pay attention to Oh, if you write the implementation of the class to copy out and then introduce back,, in fact, this time, the source code will overwrite the code in the jar package execution
TestNG Listener (i)-----The type of listener and the method used to configure---additional meta-inf detailed