/src/test/groovy/org/gradle/integtests/testng/TestNGIntegrationTest.groovy

https://github.com/danmueller/gradle · Groovy · 119 lines · 100 code · 14 blank · 5 comment · 2 complexity · ea9fad63cc0771f6a5844854d1b42bae MD5 · raw file

  1. package org.gradle.integtests.testng
  2. import org.gradle.integtests.DistributionIntegrationTestRunner
  3. import org.gradle.integtests.GradleDistribution
  4. import org.gradle.integtests.GradleExecuter
  5. import org.gradle.integtests.testng.TestNGIntegrationProject
  6. import org.junit.Test
  7. import org.junit.runner.RunWith
  8. import static org.gradle.integtests.testng.TestNGIntegrationProject.*
  9. import org.gradle.integtests.TestFile
  10. /**
  11. * @author Tom Eyckmans
  12. */
  13. @RunWith(DistributionIntegrationTestRunner.class)
  14. public class TestNGIntegrationTest {
  15. static final String GROOVY = "groovy"
  16. static final String JAVA = "java"
  17. static final String JDK14 = "jdk14"
  18. static final String JDK15 = "jdk15"
  19. static final GROOVY_JDK15_FAILING = failingIntegrationProject(GROOVY, JDK15, { name, projectDir, result ->
  20. checkExists(projectDir, 'build/classes/org/gradle/Ok.class')
  21. checkExists(projectDir, 'build/test-classes/org/gradle/BadTest.class')
  22. checkExists(projectDir, 'build/reports/tests/index.html')
  23. })
  24. static final GROOVY_JDK15_PASSING = passingIntegrationProject(GROOVY, JDK15, { name, projectDir, result ->
  25. checkExists(projectDir, 'build/classes/org/gradle/Ok.class')
  26. checkExists(projectDir, 'build/test-classes/org/gradle/OkTest.class')
  27. checkExists(projectDir, 'build/reports/tests/index.html')
  28. })
  29. static final JAVA_JDK14_FAILING = failingIntegrationProject(JAVA, JDK14, { name, projectDir, result ->
  30. checkExists(projectDir, 'build/classes/org/gradle/Ok.class')
  31. checkExists(projectDir, 'build/test-classes/org/gradle/BadTest.class')
  32. checkExists(projectDir, 'build/reports/tests/index.html')
  33. })
  34. static final JAVA_JDK14_PASSING = passingIntegrationProject(JAVA, JDK14, { name, projectDir, result ->
  35. checkExists(projectDir, 'build/classes/org/gradle/Ok.class')
  36. checkExists(projectDir, 'build/test-classes/org/gradle/OkTest.class')
  37. checkExists(projectDir, 'build/reports/tests/index.html')
  38. })
  39. static final JAVA_JDK15_FAILING = failingIntegrationProject(JAVA, JDK15, { name, projectDir, result ->
  40. checkExists(projectDir, 'build/classes/org/gradle/Ok.class')
  41. checkExists(projectDir, 'build/test-classes/org/gradle/BadTest.class')
  42. checkExists(projectDir, 'build/reports/tests/index.html')
  43. })
  44. static final JAVA_JDK15_PASSING = passingIntegrationProject(JAVA, JDK15, { name, projectDir, result ->
  45. checkExists(projectDir, 'build/classes/org/gradle/Ok.class')
  46. checkExists(projectDir, 'build/test-classes/org/gradle/OkTest.class')
  47. checkExists(projectDir, 'build/reports/tests/index.html')
  48. })
  49. static final JAVA_JDK15_PASSING_NO_REPORT = passingIntegrationProject(JAVA, JDK15, "-no-report", { name, projectDir, result ->
  50. checkExists(projectDir, 'build/classes/org/gradle/Ok.class')
  51. checkExists(projectDir, 'build/test-classes/org/gradle/OkTest.class')
  52. checkDoesNotExists(projectDir, 'build/reports/tests/index.html')
  53. })
  54. static final SUITE_XML_BUILDER = new TestNGIntegrationProject("suitexmlbuilder", false, null, { name, projectDir, result ->
  55. checkExists(projectDir, 'build/classes/org/gradle/testng/User.class')
  56. checkExists(projectDir, 'build/classes/org/gradle/testng/UserImpl.class')
  57. checkExists(projectDir, 'build/test-classes/org/gradle/testng/UserImplTest.class')
  58. checkExists(projectDir, 'build/reports/tests/index.html')
  59. checkExists(projectDir, 'build/reports/tests/emailable-report.html')
  60. })
  61. // Injected by test runner
  62. private GradleDistribution dist;
  63. private GradleExecuter executer;
  64. @Test
  65. public void suiteXmlBuilder() {
  66. checkProject(SUITE_XML_BUILDER)
  67. }
  68. @Test
  69. public void groovyJdk15() {
  70. checkProject(GROOVY_JDK15_PASSING)
  71. checkProject(GROOVY_JDK15_FAILING)
  72. }
  73. @Test
  74. public void javaJdk14() {
  75. checkProject(GROOVY_JDK15_PASSING)
  76. checkProject(GROOVY_JDK15_FAILING)
  77. }
  78. @Test
  79. public void javaJdk15() {
  80. checkProject(JAVA_JDK15_PASSING)
  81. checkProject(JAVA_JDK15_FAILING)
  82. checkProject(JAVA_JDK15_PASSING_NO_REPORT)
  83. }
  84. private def checkProject(project) {
  85. final File projectDir = new File(new File(dist.samplesDir, "testng"), project.name)
  86. def result
  87. executer.inDirectory(projectDir).withTasks('clean', 'test')
  88. if (project.expectFailure) {
  89. result = executer.runWithFailure()
  90. } else {
  91. result = executer.run()
  92. }
  93. // output: output, error: error, command: actualCommand, unixCommand: unixCommand, windowsCommand: windowsCommand
  94. project.doAssert(projectDir, result)
  95. }
  96. static File file(File baseDir, String[] path) {
  97. new File(baseDir, path.join('/'));
  98. }
  99. static void checkExists(File baseDir, String[] path) {
  100. new TestFile(baseDir, path).assertExists()
  101. }
  102. static void checkDoesNotExists(File baseDir, String[] path) {
  103. new TestFile(baseDir, path).assertDoesNotExist()
  104. }
  105. }