Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 55ee1b7

Browse files
authored
Merge pull request #8 from slu-it/test-optimization
Test optimization
2 parents 4d51faa + c8da126 commit 55ee1b7

File tree

17 files changed

+997
-566
lines changed

17 files changed

+997
-566
lines changed

pom.xml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<version.findbugs.maven.plugin>3.0.3</version.findbugs.maven.plugin>
104104
<version.license.maven.plugin>1.8</version.license.maven.plugin>
105105
<version.jacoco.maven.plugin>0.7.6.201602180812</version.jacoco.maven.plugin>
106+
<version.pitest.maven.plugin>1.1.10</version.pitest.maven.plugin>
106107

107108
</properties>
108109

@@ -287,13 +288,18 @@
287288
<groupId>org.apache.maven.plugins</groupId>
288289
<artifactId>maven-failsafe-plugin</artifactId>
289290
</plugin>
290-
291291
<plugin>
292292
<!-- record coverage metrics -->
293293
<groupId>org.jacoco</groupId>
294294
<artifactId>jacoco-maven-plugin</artifactId>
295295
</plugin>
296-
296+
297+
<plugin>
298+
<!-- execute mutation tests -->
299+
<groupId>org.pitest</groupId>
300+
<artifactId>pitest-maven</artifactId>
301+
</plugin>
302+
297303
</plugins>
298304
<pluginManagement>
299305
<plugins>
@@ -659,6 +665,21 @@
659665
</executions>
660666
</plugin>
661667

668+
<plugin>
669+
<!-- mutation testing -->
670+
<groupId>org.pitest</groupId>
671+
<artifactId>pitest-maven</artifactId>
672+
<version>${version.pitest.maven.plugin}</version>
673+
<configuration>
674+
<targetClasses>
675+
<param>info.novatec.testit.webtester.*</param>
676+
</targetClasses>
677+
<targetTests>
678+
<param>info.novatec.testit.webtester.*</param>
679+
</targetTests>
680+
</configuration>
681+
</plugin>
682+
662683
</plugins>
663684
</pluginManagement>
664685

@@ -761,26 +782,6 @@
761782
<role>developer</role>
762783
</roles>
763784
</developer>
764-
<developer>
765-
<id>pmo</id>
766-
<name>Pascal Moll</name>
767-
<email>pascal.moll@novatec-gmbh.de</email>
768-
<organization>NovaTec Consulting GmbH</organization>
769-
<organizationUrl>http://www.novatec-gmbh.de</organizationUrl>
770-
<roles>
771-
<role>developer</role>
772-
</roles>
773-
</developer>
774-
<developer>
775-
<id>benhamidene</id>
776-
<name>Anis Ben Hamidene</name>
777-
<email>anis.benhamidene@novatec-gmbh.de</email>
778-
<organization>NovaTec Consulting GmbH</organization>
779-
<organizationUrl>http://www.novatec-gmbh.de</organizationUrl>
780-
<roles>
781-
<role>developer</role>
782-
</roles>
783-
</developer>
784785
</developers>
785786

786787
</project>

webtester-support-assertj3/src/main/java/info/novatec/testit/webtester/support/assertj/WebTesterAssertions.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import org.assertj.core.api.Assertions;
44

55
import info.novatec.testit.webtester.pagefragments.Button;
6+
import info.novatec.testit.webtester.pagefragments.GenericSelect;
67
import info.novatec.testit.webtester.pagefragments.GenericTextField;
78
import info.novatec.testit.webtester.pagefragments.MultiSelect;
89
import info.novatec.testit.webtester.pagefragments.PageFragment;
910
import info.novatec.testit.webtester.pagefragments.SingleSelect;
1011
import info.novatec.testit.webtester.pagefragments.traits.Selectable;
1112
import info.novatec.testit.webtester.support.assertj.assertions.pagefragments.ButtonAssert;
13+
import info.novatec.testit.webtester.support.assertj.assertions.pagefragments.GenericSelectAssert;
1214
import info.novatec.testit.webtester.support.assertj.assertions.pagefragments.GenericTextFieldAssert;
1315
import info.novatec.testit.webtester.support.assertj.assertions.pagefragments.MultiSelectAssert;
1416
import info.novatec.testit.webtester.support.assertj.assertions.pagefragments.PageFragmentAssert;
@@ -68,6 +70,19 @@ public static ButtonAssert assertThat(Button actual) {
6870
return new ButtonAssert(actual);
6971
}
7072

73+
/**
74+
* Creates a new {@link GenericSelectAssert} for the given {@link GenericSelect}.
75+
*
76+
* @param actual the select to assert
77+
* @return the new assert instance
78+
* @see GenericSelect
79+
* @see GenericSelectAssert
80+
* @since 2.0
81+
*/
82+
public static GenericSelectAssert assertThat(GenericSelect actual) {
83+
return new GenericSelectAssert(actual, GenericSelectAssert.class);
84+
}
85+
7186
/**
7287
* Creates a new {@link SingleSelectAssert} for the given {@link SingleSelect}.
7388
*

webtester-support-assertj3/src/main/java/info/novatec/testit/webtester/support/assertj/assertions/AbstractWebTesterAssert.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@
88
*
99
* @param <A> the "self" type of this assertion class. Please read
1010
* <a href="http://bit.ly/anMa4g" target="_blank">
11-
* Emulating 'self types'using Java Generics to simplify fluent API implementation
11+
* Emulating 'self types'using Java Generics to simplify fluent API implementation
1212
* </a>
1313
* for more details.
1414
* @param <B> the type of the "actual" value.
1515
* @since 2.0
1616
*/
1717
public abstract class AbstractWebTesterAssert<A, B> extends AbstractAssert<AbstractWebTesterAssert<A, B>, B> {
1818

19-
public AbstractWebTesterAssert(B actual, Class<?> selfType) {
19+
public AbstractWebTesterAssert(B actual, Class<A> selfType) {
2020
super(actual, selfType);
2121
}
2222

23+
/**
24+
* Noop method for syntax purposes.
25+
*
26+
* @return the same Assertion instance for fluent API use.
27+
* @since 2.0
28+
*/
29+
public A and() {
30+
return ( A ) this;
31+
}
32+
2333
protected final void failOnActualBeingNull() {
2434
if (actual == null) {
2535
failWithMessage("actual is null");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
* @since 2.0
1818
*/
1919
@SuppressWarnings({ "unchecked", "rawtypes" })
20-
public abstract class AbstractSelectAssert<A extends AbstractSelectAssert, B extends GenericSelect>
20+
public class GenericSelectAssert<A extends GenericSelectAssert, B extends GenericSelect>
2121
extends AbstractPageFragmentAssert<A, B> {
2222

23-
protected AbstractSelectAssert(B actual, Class<A> selfType) {
23+
public GenericSelectAssert(B actual, Class<A> selfType) {
2424
super(actual, selfType);
2525
}
2626

webtester-support-assertj3/src/main/java/info/novatec/testit/webtester/support/assertj/assertions/pagefragments/MultiSelectAssert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @see MultiSelect
1717
* @since 2.0
1818
*/
19-
public class MultiSelectAssert extends AbstractSelectAssert<MultiSelectAssert, MultiSelect> {
19+
public class MultiSelectAssert extends GenericSelectAssert<MultiSelectAssert, MultiSelect> {
2020

2121
public MultiSelectAssert(MultiSelect actual) {
2222
super(actual, MultiSelectAssert.class);

webtester-support-assertj3/src/main/java/info/novatec/testit/webtester/support/assertj/assertions/pagefragments/SingleSelectAssert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @see SingleSelect
1515
* @since 2.0
1616
*/
17-
public class SingleSelectAssert extends AbstractSelectAssert<SingleSelectAssert, SingleSelect> {
17+
public class SingleSelectAssert extends GenericSelectAssert<SingleSelectAssert, SingleSelect> {
1818

1919
public SingleSelectAssert(SingleSelect actual) {
2020
super(actual, SingleSelectAssert.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package info.novatec.testit.webtester.support.assertj.assertions;
2+
3+
import org.assertj.core.api.Assertions;
4+
import org.junit.Test;
5+
import org.junit.experimental.runners.Enclosed;
6+
import org.junit.runner.RunWith;
7+
8+
9+
@RunWith(Enclosed.class)
10+
public class AbstractWebTesterAssertTest {
11+
12+
public static class FailOnActualBeingNull {
13+
14+
@Test
15+
public void nonNullActualPasses() {
16+
new TestAssert("foo").failOnActualBeingNull();
17+
}
18+
19+
@Test(expected = AssertionError.class)
20+
public void nullActualThrowsError() {
21+
new TestAssert(null).failOnActualBeingNull();
22+
}
23+
24+
}
25+
26+
public static class And {
27+
28+
@Test
29+
public void invocationReturnsSameAssertionInstance() {
30+
TestAssert original = new TestAssert("foo");
31+
TestAssert returned = original.and();
32+
Assertions.assertThat(returned).isSameAs(original);
33+
}
34+
35+
}
36+
37+
private static class TestAssert extends AbstractWebTesterAssert<TestAssert, String> {
38+
39+
public TestAssert(String actual) {
40+
super(actual, TestAssert.class);
41+
}
42+
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package info.novatec.testit.webtester.support.assertj.assertions.pagefragments;
2+
3+
import org.junit.Test;
4+
5+
import info.novatec.testit.webtester.pagefragments.PageFragment;
6+
7+
8+
public class AbstractPageFragmentAssertTest {
9+
10+
@Test(expected = AssertionError.class)
11+
public void nullPageFragmentsCantBeAsserted() {
12+
new TestAssert(null);
13+
}
14+
15+
private static class TestAssert extends AbstractPageFragmentAssert<TestAssert, PageFragment> {
16+
17+
public TestAssert(PageFragment actual) {
18+
super(actual, TestAssert.class);
19+
}
20+
21+
}
22+
23+
}

webtester-support-assertj3/src/test/java/info/novatec/testit/webtester/support/assertj/assertions/pagefragments/ButtonAssertTest.java

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,58 @@
55
import static org.mockito.Mockito.mock;
66

77
import org.junit.Test;
8+
import org.junit.experimental.runners.Enclosed;
89
import org.junit.runner.RunWith;
9-
import org.mockito.runners.MockitoJUnitRunner;
1010

1111
import info.novatec.testit.webtester.pagefragments.Button;
1212

1313

14-
@RunWith(MockitoJUnitRunner.class)
14+
@RunWith(Enclosed.class)
1515
public class ButtonAssertTest {
1616

17-
@Test
18-
public void hasLabelPositive() {
19-
assertThat(buttonWithLabel("foo")).hasLabel("foo");
20-
}
17+
public static class HasLabel {
2118

22-
@Test(expected = AssertionError.class)
23-
public void hasLabelNegative() {
24-
assertThat(buttonWithLabel("bar")).hasLabel("foo");
25-
}
19+
@Test
20+
public void havingLabelPasses() {
21+
assertThat(buttonWithLabel("foo")).hasLabel("foo");
22+
}
23+
24+
@Test(expected = AssertionError.class)
25+
public void notHavingLabelFails() {
26+
assertThat(buttonWithLabel("bar")).hasLabel("foo");
27+
}
28+
29+
@Test
30+
public void invocationReturnsSameAssertionInstance() {
31+
ButtonAssert original = assertThat(buttonWithLabel("foo"));
32+
ButtonAssert returned = original.hasLabel("foo");
33+
assertThat(returned).isSameAs(original);
34+
}
2635

27-
@Test
28-
public void notHasLabelPositive() {
29-
assertThat(buttonWithLabel("bar")).hasNotLabel("foo");
3036
}
3137

32-
@Test(expected = AssertionError.class)
33-
public void notHasLabelNegative() {
34-
assertThat(buttonWithLabel("foo")).hasNotLabel("foo");
38+
public static class NotHasLabel {
39+
40+
@Test
41+
public void notHavingLabelPasses() {
42+
assertThat(buttonWithLabel("bar")).hasNotLabel("foo");
43+
}
44+
45+
@Test(expected = AssertionError.class)
46+
public void havingLabelFails() {
47+
assertThat(buttonWithLabel("foo")).hasNotLabel("foo");
48+
}
49+
50+
@Test
51+
public void invocationReturnsSameAssertionInstance() {
52+
ButtonAssert original = assertThat(buttonWithLabel("bar"));
53+
ButtonAssert returned = original.hasNotLabel("foo");
54+
assertThat(returned).isSameAs(original);
55+
}
56+
3557
}
3658

37-
private Button buttonWithLabel(String label) {
59+
private static Button buttonWithLabel(String label) {
3860
Button button = mock(Button.class);
3961
doReturn(label).when(button).getLabel();
4062
return button;

0 commit comments

Comments
 (0)