微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jmeter自定义Java请求

1.引入相关依赖

<properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <jmeter-version>5.0</jmeter-version>
</properties>

<dependencies>
        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_core</artifactId>
            <version>${jmeter-version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>ApacheJMeter_java</artifactId>
            <version>${jmeter-version}</version>
            <scope>provided</scope>
        </dependency>
</dependencies>

<!--将依赖注入jar包-->
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <!-- get all project dependencies -->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!-- MainClass in mainfest make a executable jar -->
                    <archive>
                        <manifest>
                            <mainClass>util.Microseer</mainClass>
                        </manifest>
                    </archive>

                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- bind to the packaging phase -->
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

2.创建一个实现org.apache.jmeter.protocol.java.sampler.JavaSamplerClient接口的测试实现类,实现四个抽象方法

public interface JavaSamplerClient {
    
    /**
    *  测试开始前的初始化方法,如提前获取参数,以避免runTest中获取参数,减少性能开销
    */
    void setupTest(JavaSamplerContext context);

    /**
     * 测试主流程
     */
    SampleResult runTest(JavaSamplerContext context);

    /**
     * 测试流程结束后的收尾工作
     */
    void teardownTest(JavaSamplerContext context);

    /**
     * GUI界面中展示的默认参数
     */
    Arguments getDefaultParameters();
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐