forked from sbt/sbt-testng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for "integration test" sbt#10
- Loading branch information
Sherif Ebady
committed
May 30, 2018
1 parent
90ef573
commit a49b25e
Showing
8 changed files
with
186 additions
and
41 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
plugin/src/main/scala/de/johoop/testngplugin/BaseTestNGPlugin.scala
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,71 @@ | ||
/* Copyright (c) 2012-2014 Joachim Hofer & contributors. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* 3. The names of the author(s) may not be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package de.johoop.testngplugin | ||
|
||
import sbt._ | ||
|
||
private[testngplugin] abstract class BaseTestNGPlugin extends AutoPlugin { | ||
|
||
object autoImport { | ||
val testNGVersion = SettingKey[String]( | ||
"testng-version", | ||
"the version of TestNG to use") | ||
|
||
val testNGOutputDirectory = SettingKey[String]( | ||
"testng-output-directory", | ||
"the directory where the test results will be written to by TestNG") | ||
|
||
val testNGParameters = SettingKey[Seq[String]]( | ||
"testng-parameters", | ||
"additional parameters to TestNG") | ||
|
||
val testNGSuites = SettingKey[Seq[String]]( | ||
"testng-suites", | ||
"the suite definition files (YAML or XML) that will be run by TestNG") | ||
|
||
val testNGInterfaceVersion = SettingKey[String]( | ||
"testngInterfaceVersion") | ||
|
||
val testNGSnakeyamlVersion = SettingKey[String]( | ||
"testngSnakeyamlVersion", | ||
"the version of Snakeyaml to use") | ||
} | ||
|
||
lazy val testngSources: Array[Byte] = { | ||
val artifactId = TestNGPluginBuildInfo.interfaceName + "_2.12" | ||
val src = url(s"https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/${TestNGPluginBuildInfo.organization}/${artifactId}/${TestNGPluginBuildInfo.version}/srcs/${artifactId}-sources.jar") | ||
IO.withTemporaryDirectory { dir => | ||
val f = dir / "temp.jar" | ||
sbt.io.Using.urlInputStream(src) { in => | ||
IO.transfer(in, f) | ||
} | ||
IO.readBytes(f) | ||
} | ||
} | ||
|
||
override def requires = plugins.JvmPlugin | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
plugin/src/main/scala/de/johoop/testngplugin/TestNGItPlugin.scala
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,77 @@ | ||
/* Copyright (c) 2018 Joachim Hofer & contributors. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* 3. The names of the author(s) may not be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package de.johoop.testngplugin | ||
|
||
import java.io.ByteArrayInputStream | ||
import sbt._ | ||
import sbt.Keys._ | ||
|
||
object TestNGItPlugin extends BaseTestNGPlugin { | ||
|
||
import autoImport._ | ||
|
||
override lazy val projectSettings: Seq[Def.Setting[_]] = Seq( | ||
resolvers += Resolver.sbtPluginRepo("releases"), // why is that necessary, and why like that? | ||
|
||
testNGVersion := (testNGVersion ?? TestNGPluginBuildInfo.testngVersion).value, | ||
testNGSnakeyamlVersion := (testNGSnakeyamlVersion ?? "1.17").value, | ||
testNGInterfaceVersion := (testNGInterfaceVersion ?? TestNGPluginBuildInfo.version).value, | ||
testNGOutputDirectory := (crossTarget.value / "testng").absolutePath, | ||
testNGParameters := Seq(), | ||
testNGSuites := Seq(((resourceDirectory in IntegrationTest).value / "testng.yaml").absolutePath), | ||
|
||
libraryDependencies ++= Seq( | ||
"org.testng" % "testng" % testNGVersion.value % "test,it", | ||
"org.yaml" % "snakeyaml" % testNGSnakeyamlVersion.value % "test,it" | ||
), | ||
|
||
libraryDependencies += { | ||
if (TestNGPluginBuildInfo.preCompiledInterfaceVersions.contains(scalaBinaryVersion.value)) { | ||
TestNGPluginBuildInfo.organization %% TestNGPluginBuildInfo.interfaceName % testNGInterfaceVersion.value % "test,it" | ||
} else { | ||
"org.scala-sbt" % "test-interface" % "1.0" % "test,it" | ||
} | ||
}, | ||
|
||
sourceGenerators in IntegrationTest += Def.task { | ||
val dir = (sourceManaged in IntegrationTest).value | ||
if (TestNGPluginBuildInfo.preCompiledInterfaceVersions.contains(scalaBinaryVersion.value)) { | ||
Nil | ||
} else { | ||
IO.unzipStream(new ByteArrayInputStream(testngSources), dir).toList.filter(_.getName endsWith "scala") | ||
} | ||
}, | ||
|
||
testFrameworks += TestNGFrameworkID, | ||
|
||
testOptions += Tests.Argument( | ||
TestNGFrameworkID, ("-d" +: testNGOutputDirectory.value +: testNGParameters.value) ++ testNGSuites.value: _* | ||
) | ||
) | ||
|
||
lazy val TestNGFrameworkID = new TestFramework("de.johoop.testnginterface.TestNGFramework") | ||
|
||
} |
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
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 @@ | ||
lazy val root = (project in file(".")) | ||
.configs(IntegrationTest) | ||
.settings( | ||
Defaults.itSettings | ||
) | ||
|
||
enablePlugins(TestNGItPlugin) | ||
|
||
crossScalaVersions := Seq("2.10.6", "2.11.11", "2.12.3") |
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 @@ | ||
addSbtPlugin("de.johoop" % "sbt-testng-plugin" % System.getProperty("plugin.version")) |
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,5 @@ | ||
name: Foo | ||
tests: | ||
- name: Baz | ||
classes: | ||
- example.ITest1 |
17 changes: 17 additions & 0 deletions
17
plugin/src/sbt-test/testng/it/src/it/scala/example/ITest1.scala
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,17 @@ | ||
package example; | ||
|
||
import org.testng.annotations.Test | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
import scala.util.Properties | ||
|
||
class ITest1 { | ||
|
||
@Test | ||
def foo(): Unit = { | ||
val version = Properties.versionNumberString | ||
val path = Paths.get(version + ".txt") | ||
Files.write(path, version.getBytes("UTF-8")) | ||
} | ||
|
||
} |
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,4 @@ | ||
> + it:test | ||
$ exists 2.10.6.txt | ||
$ exists 2.11.11.txt | ||
$ exists 2.12.3.txt |