Skip to content

Commit 3932345

Browse files
committed
Ability to use QuickPerf with TestNG
1 parent 4e1d09d commit 3932345

27 files changed

+1330
-0
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
<module>sql</module>
163163
<module>junit4</module>
164164
<module>junit5</module>
165+
<module>testng</module>
165166
<module>spring</module>
166167
</modules>
167168
</profile>
@@ -173,6 +174,7 @@
173174
<module>sql/sql-annotations</module>
174175
<module>junit4/junit4-runner</module>
175176
<module>junit5/junit5-extension</module>
177+
<module>testng/testng-listener</module>
176178
<module>spring/junit4-spring3</module>
177179
<module>spring/junit4-spring4</module>
178180
<module>spring/junit4-spring5</module>

testng/pom.xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
~ the License. You may obtain a copy of the License at
5+
~
6+
~ http://www.apache.org/licenses/LICENSE-2.0
7+
~
8+
~ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
~ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
~ specific language governing permissions and limitations under the License.
11+
~
12+
~ Copyright 2019-2019 the original author or authors.
13+
-->
14+
15+
<project xmlns="http://maven.apache.org/POM/4.0.0"
16+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<parent>
19+
<groupId>org.quickperf</groupId>
20+
<artifactId>quick-perf</artifactId>
21+
<version>1.0-SNAPSHOT</version>
22+
</parent>
23+
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<artifactId>quick-perf-testng-parent</artifactId>
27+
28+
<packaging>pom</packaging>
29+
30+
<properties>
31+
<maven.compiler.source>8</maven.compiler.source>
32+
<maven.compiler.target>8</maven.compiler.target>
33+
<dependencies.max.jdk.version>8</dependencies.max.jdk.version>
34+
</properties>
35+
36+
<modules>
37+
<module>testng-listener</module>
38+
<module>testng-test-util</module>
39+
<module>testng-sql-test</module>
40+
<module>testng-jvm-test</module>
41+
</modules>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<artifactId>maven-surefire-plugin</artifactId>
47+
<version>${maven-surefire-plugin.version}</version>
48+
<configuration>
49+
<parallel>all</parallel>
50+
<threadCount>5</threadCount>
51+
<includes>
52+
<include>**/*Test.java</include>
53+
</includes>
54+
</configuration>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
59+
</project>

testng/testng-jvm-test/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!--
2+
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
~ the License. You may obtain a copy of the License at
4+
~
5+
~ http://www.apache.org/licenses/LICENSE-2.0
6+
~
7+
~ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
~ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
~ specific language governing permissions and limitations under the License.
10+
~
11+
~ Copyright 2019-2019 the original author or authors.
12+
-->
13+
14+
<project xmlns="http://maven.apache.org/POM/4.0.0"
15+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
16+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
17+
<parent>
18+
<groupId>org.quickperf</groupId>
19+
<artifactId>quick-perf-testng-parent</artifactId>
20+
<version>1.0-SNAPSHOT</version>
21+
</parent>
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<artifactId>quick-perf-testng-jvm-test</artifactId>
25+
26+
<properties>
27+
<jar.skipIfEmpty>true</jar.skipIfEmpty>
28+
<maven.install.skip>true</maven.install.skip>
29+
</properties>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>org.testng</groupId>
34+
<artifactId>testng</artifactId>
35+
<version>7.0.0</version>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.quickperf</groupId>
40+
<artifactId>quick-perf-testng</artifactId>
41+
<version>1.0-SNAPSHOT</version>
42+
<scope>test</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.quickperf</groupId>
46+
<artifactId>quick-perf-testng-test-util</artifactId>
47+
<version>1.0-SNAPSHOT</version>
48+
<classifier>tests</classifier>
49+
<type>test-jar</type>
50+
<scope>test</scope>
51+
</dependency>
52+
</dependencies>
53+
54+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2019 the original author or authors.
12+
*/
13+
14+
package org.quickperf.testng.jvm.allocation;
15+
16+
import org.quickperf.testng.TestNGTests;
17+
import org.quickperf.testng.TestNGTests.TestNGTestsResult;
18+
import org.testng.annotations.Test;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
22+
public class AllocationAnnotationsTestNGTest {
23+
24+
@Test public void
25+
test_should_fail_if_allocation_is_greater_than_expected() {
26+
27+
// GIVEN
28+
Class<?> testClass = TestNGClassWithMethodAnnotatedWithExpectMaxHeapAllocation.class;
29+
TestNGTests testNGTests = TestNGTests.createInstance(testClass);
30+
31+
// WHEN
32+
TestNGTestsResult testsResult = testNGTests.run();
33+
34+
// THEN
35+
assertThat(testsResult.getNumberOfFailedTest()).isEqualTo(1);
36+
37+
Throwable errorReport = testsResult.getThrowableOfFirstTest();
38+
assertThat(errorReport).hasMessageContaining(
39+
"Expected allocation to be less than 439.0 bytes but is 440.0 bytes");
40+
41+
}
42+
43+
@Test
44+
public void test_should_fail_if_test_method_annotated_with_no_allocation_allocates() {
45+
46+
// GIVEN
47+
Class<?> testClass = TestNGClassWithAMethodAllocatingAndAnnotatedWithExpectNoHeapAllocation.class;
48+
TestNGTests testNGTests = TestNGTests.createInstance(testClass);
49+
50+
// WHEN
51+
TestNGTestsResult testsResult = testNGTests.run();
52+
53+
// THEN
54+
assertThat(testsResult.getNumberOfFailedTest()).isEqualTo(1);
55+
56+
assertThat(testsResult.getThrowableOfFirstTest()).hasMessageContaining(
57+
"Expected allocation to be 0 but is 440.0 bytes");
58+
59+
}
60+
61+
@Test
62+
public void test_should_not_fail_with_a_method_without_allocation_and_annotated_with_no_allocation() {
63+
64+
// GIVEN
65+
Class<?> testClass = TestNGClassWithAMethodNotAllocatingAndAnnotatedWithExpectNoHeapAllocation.class;
66+
TestNGTests testNGTests = TestNGTests.createInstance(testClass);
67+
68+
// WHEN
69+
TestNGTestsResult testsResult = testNGTests.run();
70+
71+
// THEN
72+
assertThat(testsResult.getNumberOfPassedTest()).isEqualTo(1);
73+
74+
}
75+
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2019 the original author or authors.
12+
*/
13+
14+
package org.quickperf.testng.jvm.allocation;
15+
16+
import org.quickperf.jvm.annotations.ExpectNoHeapAllocation;
17+
import org.quickperf.jvm.annotations.JvmOptions;
18+
import org.testng.annotations.Test;
19+
20+
import java.util.ArrayList;
21+
22+
public class TestNGClassWithAMethodAllocatingAndAnnotatedWithExpectNoHeapAllocation {
23+
24+
@ExpectNoHeapAllocation
25+
@JvmOptions("-XX:+UseCompressedOops -XX:+UseCompressedClassPointers")
26+
@Test
27+
public void method_allocating() {
28+
ArrayList<Object> data = new ArrayList<>(100);
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2019 the original author or authors.
12+
*/
13+
14+
package org.quickperf.testng.jvm.allocation;
15+
16+
import org.quickperf.jvm.annotations.ExpectNoHeapAllocation;
17+
import org.quickperf.jvm.annotations.JvmOptions;
18+
import org.testng.annotations.Test;
19+
20+
public class TestNGClassWithAMethodNotAllocatingAndAnnotatedWithExpectNoHeapAllocation {
21+
22+
@ExpectNoHeapAllocation
23+
@JvmOptions("-XX:+UseCompressedOops -XX:+UseCompressedClassPointers")
24+
@Test
25+
public void method_without_allocation() {
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2019 the original author or authors.
12+
*/
13+
14+
package org.quickperf.testng.jvm.allocation;
15+
16+
import org.quickperf.jvm.allocation.AllocationUnit;
17+
import org.quickperf.jvm.annotations.ExpectMaxHeapAllocation;
18+
import org.quickperf.jvm.annotations.JvmOptions;
19+
import org.testng.annotations.Test;
20+
21+
import java.util.ArrayList;
22+
23+
public class TestNGClassWithMethodAnnotatedWithExpectMaxHeapAllocation {
24+
25+
@ExpectMaxHeapAllocation(value = 439, unit = AllocationUnit.BYTE)
26+
@JvmOptions("-XX:+UseCompressedOops -XX:+UseCompressedClassPointers")
27+
@Test
28+
public void array_list_with_size_100_should_allocate_440_bytes() {
29+
ArrayList<Object> data = new ArrayList<>(100);
30+
}
31+
32+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2019 the original author or authors.
12+
*/
13+
14+
package org.quickperf.testng.jvm.jmc;
15+
16+
import org.quickperf.testng.TestNGTests;
17+
import org.testng.annotations.Test;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
public class JmcTestNGTests {
22+
23+
@Test public void
24+
jmc_rules_having_score_greater_than_expected() {
25+
26+
// GIVEN
27+
Class<?> testClass = TestNGClassWithFailingJmcRules.class;
28+
TestNGTests testNGTests = TestNGTests.createInstance(testClass);
29+
30+
// WHEN
31+
TestNGTests.TestNGTestsResult testsResult = testNGTests.run();
32+
33+
// THEN
34+
assertThat(testsResult.getNumberOfFailedTest()).isEqualTo(1);
35+
36+
Throwable errorReport = testsResult.getThrowableOfFirstTest();
37+
assertThat(errorReport).hasMessageContaining("JMC rules are expected to have score less than <50>.")
38+
.hasMessageContaining("Rule: Primitive To Object Conversion");
39+
40+
}
41+
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
3+
* the License. You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
* specific language governing permissions and limitations under the License.
10+
*
11+
* Copyright 2019-2019 the original author or authors.
12+
*/
13+
14+
package org.quickperf.testng.jvm.jmc;
15+
16+
import org.quickperf.jvm.allocation.AllocationUnit;
17+
import org.quickperf.jvm.annotations.ExpectNoJvmIssue;
18+
import org.quickperf.jvm.annotations.HeapSize;
19+
import org.testng.annotations.Test;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
public class TestNGClassWithFailingJmcRules {
25+
26+
private static class IntegerAccumulator {
27+
28+
private List<Integer> integerList;
29+
30+
void accumulateInteger(int numberOfIntegers) {
31+
integerList = new ArrayList<>(numberOfIntegers);
32+
for (int i = 1; i <= numberOfIntegers; i++) {
33+
integerList.add(i);
34+
}
35+
}
36+
37+
}
38+
39+
@HeapSize(value = 100, unit = AllocationUnit.MEGA_BYTE)
40+
@ExpectNoJvmIssue(score = 50)
41+
@Test
42+
public void code_with_scores_of_jmc_rules_greater_than_50() {
43+
44+
IntegerAccumulator integerAccumulator = new IntegerAccumulator();
45+
integerAccumulator.accumulateInteger(3_000_000);
46+
47+
}
48+
49+
}

0 commit comments

Comments
 (0)