-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue/10: Improve unit test coverage for skippy/skippy-gradle
- Loading branch information
Showing
14 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
skippy-gradle/src/test/java/io/skippy/gradle/SkippyPluginSmokeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.skippy.gradle; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
/** | ||
* Functional test for the Getting Started With Gradle & JUnit 5 Tutorial. | ||
* | ||
* @author Florian McKee | ||
*/ | ||
public class SkippyPluginSmokeTest { | ||
|
||
@Test | ||
public void runTestsWithoutAnalysis() throws Exception { | ||
|
||
var buildFile = new File(getClass().getResource("skippyplugin/build.gradle").toURI()); | ||
var projectDir = buildFile.getParentFile(); | ||
|
||
BuildResult result = GradleRunner.create() | ||
.withProjectDir(projectDir) | ||
.withPluginClasspath() | ||
.withArguments("-b", "build-with-plugin.gradle", "clean", "build", "skippyAnalyze") | ||
.forwardOutput() | ||
.build(); | ||
|
||
var output = result.getOutput(); | ||
|
||
assertThat(output).contains(""" | ||
> Task :skippyCoverage_com.example.LeftPadderTest | ||
Capturing coverage data for com.example.LeftPadderTest in skippy/com.example.LeftPadderTest.csv | ||
> Task :skippyCoverage_com.example.RightPadderTest | ||
Capturing coverage data for com.example.RightPadderTest in skippy/com.example.RightPadderTest.csv | ||
> Task :skippyAnalyze | ||
Creating the Skippy analysis file skippy/analyzedFiles.txt."""); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/build-with-plugin.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id 'io.skippy' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' | ||
} | ||
|
||
test { | ||
testLogging { | ||
events "passed", "skipped", "failed" | ||
showStandardStreams = true | ||
exceptionFormat "full" | ||
} | ||
useJUnitPlatform() | ||
} |
22 changes: 22 additions & 0 deletions
22
skippy-gradle/src/test/resources/io/skippy/gradle/skippyplugin/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
id 'java' | ||
id 'jacoco' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' | ||
} | ||
|
||
test { | ||
testLogging { | ||
events "passed", "skipped", "failed" | ||
showStandardStreams = true | ||
exceptionFormat "full" | ||
} | ||
useJUnitPlatform() | ||
} |
Empty file.
9 changes: 9 additions & 0 deletions
9
...rc/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/LeftPadder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example; | ||
|
||
class LeftPadder { | ||
|
||
static String padLeft(String input, int size) { | ||
return StringUtils.padLeft(input, size); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...c/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/RightPadder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example; | ||
|
||
class RightPadder { | ||
|
||
static String padRight(String input, int size) { | ||
return StringUtils.padRight(input, size); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...c/test/resources/io/skippy/gradle/skippyplugin/src/main/java/com/example/StringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example; | ||
|
||
class StringUtils { | ||
|
||
/** | ||
* Pads a {@index input} string on the left with blanks until the size is equal or greater to {@index size}. | ||
*/ | ||
static String padLeft(String input, int size) { | ||
if (input.length() < size) { | ||
return padLeft(" " + input, size); | ||
} | ||
return input; | ||
} | ||
|
||
/** | ||
* Pads a {@index input} string on the right with blanks until the size is equal or greater to {@index size}. | ||
*/ | ||
static String padRight(String input, int size) { | ||
if (input.length() < size) { | ||
return padRight(input + " ", size); | ||
} | ||
return input; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...c/test/resources/io/skippy/gradle/skippyplugin/src/main/java/io/skippy/junit5/Skippy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.skippy.junit5; | ||
|
||
import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
import org.junit.jupiter.api.extension.ExecutionCondition; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
/** | ||
* Decides whether a test case needs to run based on a {@link SkippyAnalysis}. | ||
* | ||
* @author Florian McKee | ||
*/ | ||
public class Skippy implements ExecutionCondition { | ||
|
||
@Override | ||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
return ConditionEvaluationResult.enabled(""); | ||
} | ||
|
||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...dle/src/test/resources/io/skippy/gradle/skippyplugin/src/main/resources/log4j2.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
status = warn | ||
name = PropertiesConfig | ||
|
||
appender.console.type = Console | ||
appender.console.name = ConsoleAppender | ||
appender.console.layout.type = PatternLayout | ||
appender.console.layout.pattern = %-5level %logger{1.} - %msg%n | ||
|
||
rootLogger.level = warn | ||
rootLogger.appenderRefs = console | ||
rootLogger.appenderRef.console.ref = ConsoleAppender | ||
|
||
logger.com_example.name = io.skippy | ||
logger.com_example.level = debug |
18 changes: 18 additions & 0 deletions
18
...est/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/LeftPadderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example; | ||
|
||
import io.skippy.junit5.Skippy; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@ExtendWith(Skippy.class) | ||
public class LeftPadderTest { | ||
|
||
@Test | ||
void testPadLeft() { | ||
var input = TestConstants.HELLO; | ||
assertEquals(" hello", LeftPadder.padLeft(input, 6)); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...st/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/RightPadderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example; | ||
|
||
import io.skippy.junit5.Skippy; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@ExtendWith(Skippy.class) | ||
public class RightPadderTest { | ||
|
||
@Test | ||
void testPadLeft() { | ||
var input = TestConstants.HELLO; | ||
assertEquals("hello ", RightPadder.padRight(input, 6)); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...st/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/StringUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class StringUtilsTest { | ||
|
||
@Test | ||
void testPadLeft() { | ||
var input = TestConstants.HELLO; | ||
assertEquals(" hello", StringUtils.padLeft(input, 6)); | ||
} | ||
|
||
@Test | ||
void testPadRight() { | ||
var input = TestConstants.HELLO; | ||
assertEquals("hello ", StringUtils.padRight(input, 6)); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...test/resources/io/skippy/gradle/skippyplugin/src/test/java/com/example/TestConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example; | ||
|
||
class TestConstants { | ||
|
||
static final String HELLO = "hello"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters