TestNG Monitor (one)-----listener, type and configuration used---additional meta-inf explained in detail

Source: Internet
Author: User
Tags testng

Original articles, all rights reserved. Reprint, Attribution: http://blog.csdn.net/wanghantong/article/details/40404939


TESTNG provides listeners and intercepts multiple interfaces to develop our own extensions. By implementing these interfaces, we define the behavior we want in the test.

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)

Original article, All rights reserved, agree to reprint. Mark Source: http://blog.csdn.net/wanghantong/article/details/40404939

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

Such a way is often used in our development

2. Configuration files

In the configuration file we can pass

<listeners>
<listener class-name= "full class name" ></listener>
</listeners>

For plug-and-pull configuration, this way is more flexible. More convenient than the first type of writing to die in code

3. By way of Serviceloader

This is a more complex approach, and many others are used in writing an extended framework. For example, our enhancements to the testng are then encapsulated into frames that are provided for others to use

When it comes to packing, it's a thing to say. Meta-inf, in fact we often see this in project files, but it seems that some people do not know its role.

Before I studied the testng function, I was part of this.

The following first said Meta-inf

It includes, for example, the following files/directories

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 includes the location declaration in the application or extension package. It is part of the Jarindex implementation and is typically used by class loader to speed up the loading process of a class

3.X.SF------The signature file for the jar file

4.X.DSA------The signature block file, with the same file name associated with the signature file. This file stores the signature digest and the signature file is the same.

5.services/------This folder is used to store configuration files for all business supply sources

These files or directories can be proactively identified and interpreted by the Java 2 platform and configured into applications, extensions, class loader, and business


The next thing we do is to extend the implementation class (. Class) of the interface that we have written. and Meta-inf in the same folder, remember that the class is assumed to have a package name. Then the meta-inf is the root folder of the package.

Then we create the Services folder in Meta-inf. Create a file in the middle. The file name is the name of the interface that we implement. The contents of the file are written in the full folder of our implementation class

Package Meta-inf and class files to generate a jar file

Now that's over, we just need to add the generated jar package to the project.

Note: Assuming that we operate in the IDE, then we need to be aware of oh, assuming that you copy the written implementation class and then introduce it back. , and, in fact, at this time. The code in the source code is the one that overwrites the code in the jar package.


Original article. Copyright all, agree to reprint. Mark Source: http://blog.csdn.net/wanghantong/article/details/40404939


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

TestNG Monitor (one)-----listener, type and configuration used---additional meta-inf explained in detail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.