Skip to content

Commit

Permalink
issue/10: Improve unit test coverage for skippy/skippy-gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
fmck3516 committed Nov 27, 2023
1 parent 1b0351d commit 5059014
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 0 deletions.
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.""");
}

}
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()
}
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.
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);
}

}
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);
}

}
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;
}
}
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("");
}


}
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
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));
}

}
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));
}

}
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));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example;

class TestConstants {

static final String HELLO = "hello";

}
3 changes: 3 additions & 0 deletions skippy-junit5/src/main/java/io/skippy/junit5/Skippy.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class Skippy implements ExecutionCondition {

private final SkippyAnalysis skippyAnalysis;

/**
* Comment to make the JavaDoc task happy.
*/
public Skippy() {
this(SkippyAnalysis.parse());
}
Expand Down

0 comments on commit 5059014

Please sign in to comment.