Author: boisvert
Date: Sun Nov 13 19:37:00 2011
New Revision: 1201486
URL: http://svn.apache.org/viewvc?rev=1201486&view=rev
Log:
Added: MultiTest framework that allows combining multiple test frameworks for
a single project.
Modified:
buildr/trunk/CHANGELOG
buildr/trunk/lib/buildr/java/tests.rb
buildr/trunk/spec/java/tests_spec.rb
Modified: buildr/trunk/CHANGELOG
URL:
http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1201486&r1=1201485&r2=1201486&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Sun Nov 13 19:37:00 2011
@@ -1,4 +1,6 @@
1.4.7 (Pending)
+* Added: MultiTest framework that allows combining multiple test frameworks
+ for a single project.
* Added: Scala Specs2 framework support.
* Change: Scala Specs upgraded to 1.6.9 if using Scala 2.9.1
* Fixed: ArtifactNamespace fails when using artifacts with classfier.
Modified: buildr/trunk/lib/buildr/java/tests.rb
URL:
http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/java/tests.rb?rev=1201486&r1=1201485&r2=1201486&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/java/tests.rb (original)
+++ buildr/trunk/lib/buildr/java/tests.rb Sun Nov 13 19:37:00 2011
@@ -358,8 +358,67 @@ module Buildr
end
+ # A composite test framework that runs multiple other test frameworks.
+ #
+ # e.g.,
+ # test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ], :options = {
+ # :junit => { :fork => true },
+ # :testng => { ... }
+ # }
+ #
+ class MultiTest < Buildr::TestFramework::Java
+ # TODO: Support multiple test report locations, one per framework
+
+ class << self
+ def applies_to?(project) #:nodoc:
+ false # no auto-detection, should be set explicitly
+ end
+ end
+
+ attr_accessor :frameworks
+
+ def initialize(task, options) #:nodoc:
+ super
+ fail "Missing :frameworks option" unless options[:frameworks]
+ @frameworks = options[:frameworks].map do |f|
+ framework_options = (options[:options] || {})[f.to_sym] || {}
+ f.new(task, options)
+ end
+ end
+
+ def dependencies #:nodoc:
+ unless @dependencies
+ @dependencies = TestFramework::Java.dependencies
+ @dependencies += @frameworks.map { |f| f.dependencies }.flatten
+ end
+ @dependencies
+ end
+
+
+ def tests(dependencies)
+ @frameworks.map { |f| f.tests(dependencies) }.flatten
+ end
+
+ def run(tests, dependencies) #:nodoc:
+ framework_for_test = @frameworks.inject({}) do |hash, f|
+ f.tests(dependencies).each { |t| hash[t] = f }
+ hash
+ end
+
+ tests_by_framework = tests.group_by { |t| framework_for_test[t] }
+
+ passed = []
+ tests_by_framework.each do |f, tests|
+ passed += f.run(tests, dependencies)
+ end
+ passed
+ end
+ end # MultiTest
+
end # Buildr
Buildr::TestFramework << Buildr::JUnit
Buildr::TestFramework << Buildr::TestNG
+Buildr::TestFramework << Buildr::MultiTest
+
Modified: buildr/trunk/spec/java/tests_spec.rb
URL:
http://svn.apache.org/viewvc/buildr/trunk/spec/java/tests_spec.rb?rev=1201486&r1=1201485&r2=1201486&view=diff
==============================================================================
--- buildr/trunk/spec/java/tests_spec.rb (original)
+++ buildr/trunk/spec/java/tests_spec.rb Sun Nov 13 19:37:00 2011
@@ -535,3 +535,148 @@ describe Buildr::TestNG do
lambda { project('foo').test.invoke }.should_not raise_error
end
end
+
+describe Buildr::MultiTest do
+ it 'should be selectable in project' do
+ define 'foo' do
+ test.using(:multitest, :frameworks => [])
+ test.framework.should eql(:multitest)
+ end
+ end
+
+ it 'should include dependencies of whichever test framework(s) are selected'
do
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ] }
+ project('foo').test.compile.dependencies.should
include(artifact("junit:junit:jar:#{JUnit.version}"))
+ project('foo').test.compile.dependencies.should
include(artifact("org.testng:testng:jar:jdk15:#{TestNG.version}"))
+ project('foo').test.dependencies.should
include(artifact("junit:junit:jar:#{JUnit.version}"))
+ project('foo').test.dependencies.should
include(artifact("org.testng:testng:jar:jdk15:#{TestNG.version}"))
+ end
+
+ it 'should include classes of given test framework(s)' do
+ write 'src/test/java/com/example/JUnitTest.java', <<-JAVA
+ package com.example;
+ public class JUnitTest extends junit.framework.TestCase {
+ public void testNothing() { }
+ }
+ JAVA
+ write 'src/test/java/com/example/TestNGTest.java', <<-JAVA
+ package com.example;
+ @org.testng.annotations.Test
+ public class TestNGTest { }
+ JAVA
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ] }
+ project('foo').test.invoke
+ project('foo').test.tests.should include('com.example.JUnitTest',
'com.example.TestNGTest')
+ end
+
+ it 'should pass when test case passes' do
+ write 'src/test/java/PassingTest.java', <<-JAVA
+ public class PassingTest extends junit.framework.TestCase {
+ public void testNothing() {}
+ }
+ JAVA
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ] }
+ lambda { project('foo').test.invoke }.should_not raise_error
+ end
+
+ it 'should fail when test case fails' do
+ write 'src/test/java/FailingTest.java', <<-JAVA
+ public class FailingTest {
+ @org.testng.annotations.Test
+ public void testNothing() {
+ org.testng.AssertJUnit.assertTrue(false);
+ }
+ }
+ JAVA
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ] }
+ lambda { project('foo').test.invoke }.should raise_error(RuntimeError,
/Tests failed/)
+ end
+
+ it 'should fail when multiple test case fail' do
+ write 'src/test/java/FailingTest1.java', <<-JAVA
+ public class FailingTest1 {
+ @org.testng.annotations.Test
+ public void testNothing() {
+ org.testng.AssertJUnit.assertTrue(false);
+ }
+ }
+ JAVA
+ write 'src/test/java/FailingTest2.java', <<-JAVA
+ public class FailingTest2 {
+ @org.testng.annotations.Test
+ public void testNothing() {
+ org.testng.AssertJUnit.assertTrue(false);
+ }
+ }
+ JAVA
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ] }
+ lambda { project('foo').test.invoke }.should raise_error(RuntimeError,
/Tests failed/)
+ end
+
+ it 'should report failed test names' do
+ write 'src/test/java/FailingTest.java', <<-JAVA
+ public class FailingTest {
+ @org.testng.annotations.Test
+ public void testNothing() {
+ org.testng.AssertJUnit.assertTrue(false);
+ }
+ }
+ JAVA
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ] }
+ project('foo').test.invoke rescue nil
+ project('foo').test.failed_tests.should include('FailingTest')
+ end
+
+ it 'should generate reports' do
+ write 'src/test/java/PassingTest.java', <<-JAVA
+ public class PassingTest {
+ @org.testng.annotations.Test
+ public void testNothing() {}
+ }
+ JAVA
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ] }
+ lambda { project('foo').test.invoke }.should change {
+ p Dir['./**/*'].inspect
+ File.exist?('reports/multitest/foo/index.html') }.to(true)
+ end
+
+ it 'should include classes using TestNG annotations marked with a specific
group' do
+ write 'src/test/java/com/example/AnnotatedClass.java', <<-JAVA
+ package com.example;
+ @org.testng.annotations.Test(groups={"included"})
+ public class AnnotatedClass { }
+ JAVA
+ write 'src/test/java/com/example/AnnotatedMethod.java', <<-JAVA
+ package com.example;
+ public class AnnotatedMethod {
+ @org.testng.annotations.Test
+ public void annotated() {
+ org.testng.AssertJUnit.assertTrue(false);
+ }
+ }
+ JAVA
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ], :groups=>['included'] }
+ lambda { project('foo').test.invoke }.should_not raise_error
+ end
+
+ it 'should exclude classes using TestNG annotations marked with a specific
group' do
+ write 'src/test/java/com/example/AnnotatedClass.java', <<-JAVA
+ package com.example;
+ @org.testng.annotations.Test(groups={"excluded"})
+ public class AnnotatedClass {
+ public void annotated() {
+ org.testng.AssertJUnit.assertTrue(false);
+ }
+ }
+ JAVA
+ write 'src/test/java/com/example/AnnotatedMethod.java', <<-JAVA
+ package com.example;
+ public class AnnotatedMethod {
+ @org.testng.annotations.Test(groups={"included"})
+ public void annotated() {}
+ }
+ JAVA
+ define('foo') { test.using :multitest, :frameworks => [ Buildr::JUnit,
Buildr::TestNG ], :excludegroups=>['excluded'] }
+ lambda { project('foo').test.invoke }.should_not raise_error
+ end
+end