0

I want to run JUnit tests for the performance testing using JMeter Maven Plugin.

During the JUnit tests run, I use one external properties file located inside <project>/src/resources/env.properties

This file has some configuration which I need to run the tests successfully.

I have given this file in src/test/jmeter location as well but the plugin is not picking up this file.

During performance tests run using JMeter Maven Plugin, This file is not found because of the relative path given inside JUnit tests as

String fileName = "src/resources/env.properties";

I get the below error during the JMeter test run

[INFO] fileName = env.properties
[INFO] java.io.FileNotFoundException: src/resources/env.properties (No such file or directory)

Can you please help, where to give the location of this file? do I need to give in pom.xml?

These tests working perfectly fine using the JMeter application where I put this file under <JMeterApp>/bin/src/resources and run the test.

Please find below pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com</groupId>
    <artifactId>myProject</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>MyProject</name>
    <url>http://maven.apache.org</url>

    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <!-- Generate JMeter configuration -->
                    <execution>
                        <id>configuration</id>
                        <goals>
                            <goal>configure</goal>
                        </goals>
                    </execution>
                    <!-- Run JMeter tests -->
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                    <!-- Fail build on errors in test -->
                    <execution>
                        <id>jmeter-check-results</id>
                        <goals>
                            <goal>results</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generateReports>true</generateReports>
                    <jmeterExtensions>
                        <artifact>kg.apc:jmeter-plugins:pom:1.4.0</artifact>
                        <artifact>kg.apc:jmeter-plugins-json:2.7</artifact>
                    </jmeterExtensions>
                    <junitLibraries>
                        <artifact>com:myProject:1.0-SNAPSHOT</artifact>
                    </junitLibraries>
                    <propertiesFilesDirectory>src/test/jmeter/src/resources</propertiesFilesDirectory>
                    <downloadExtensionDependencies>false</downloadExtensionDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
Kushal Shinde
  • 715
  • 7
  • 15

1 Answers1

1

When you run your tests via JMeter Maven Plugin the current working directory looks like:

your_project\target\some-guid-like-structure\jmeter\bin

so in order to access the file which lives under your_project\src\resources you need to refer it like:

String fileName = "../../../../src/resources/env.properties";

More information: How to Use the JMeter Maven Plugin

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • I am unclear this part `String fileName = "../../../../src/resources/env.properties";` Could you please elaborate more? – Kushal Shinde Jul 14 '21 at 19:18
  • `../` means go up a directory, so this is going up 4 directories to your project base directory. There is also the the maven property `${project.basedir}` which could be used instead of traversing up the directory structure. If you want to access it from java code create a properties file in your resources directory and define a property that looks like `baseDirectory=${project.basedir}`. You can load in your properties file and use `props.get("baseDirectory")` to get the absolute URL of your project base directory. – Ardesco Sep 09 '21 at 20:03