Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How could JQF handle environment variables & system properties from Maven Surefire? #198

Closed
shuaiwang516 opened this issue Jul 21, 2022 · 1 comment

Comments

@shuaiwang516
Copy link
Contributor

shuaiwang516 commented Jul 21, 2022

Some tests will run with environment variables and system properties that are set in Maven Surefire from the Maven pom.xml file.

However, those environment variables and system properties are not considered by JQF.

A very simple example:

  public void testA(String s) {
    String s1 = System.getProperty("test.prefix") + s;  
    assertEquals("test-" + s, s1);
  }

In pom.xml file:

<build>
  <plugins>
      ...
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
              <systemPropertyVariables>
                  <test.prefix>test-</test.prefix>       <!-- test.prefix = "test-" -->
              </systemPropertyVariables>
          </configuration>
      </plugin>
      ...
  </plugins>
</build>

This simple example can pass with mvn test but will fail with JQF because JQF does not set the system property.
We can fix this by simply adding -Dtest.prefix=test-, but would it be better to make a configurable feature so that JQF can also set the env. vars. and sys. properties from those are set in Maven Surefire?

@shuaiwang516 shuaiwang516 changed the title How could JQF handle envrionment variables & system properties from maven surefire? How could JQF handle environment variables & system properties from Maven Surefire? Jul 22, 2022
@rohanpadhye
Copy link
Owner

That's an interesting observation! Thanks for the example.

I agree that the JQF plugin will not pick up these properties. The reason is simple: mvn jqf:fuzz runs a different plugin than Surefire. While the JQF test framework depends on JUnit and picks up all JUnit configurations (such as the @Before/@After annotations and others), the JQF Maven Plugin is not related to the Surefire plugin. I don't even know if Maven plugins can have inheritance relationships. So, any Surefire-specific configurations will not carry over to JQF.

There are many ways to get around this issue. Simply specify the properties in a different area in the pom.xml; that is, not specific to Surefire. For example, you can directly put a <properties> tag under <project>. If you want the properties to only be set during testing, you can use a <profile> that is set only when running tests. I think there is also a Maven Properties Plugin that can be configured to bind to a particular Maven phase, where you also run JQF.

If you know of a way to have the JQF plugin inherit configuration from Surefire, do let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants