Snippet Preview
Snippet HTML Code
1
/*
2
* JBoss, Home of Professional Open Source
3
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
6
*
7
* Licensed under the Apache License, Version 2.0 (the "License");
8
* you may not use this file except in compliance with the License.
9
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
package org.jboss.arquillian.testng.container;
18
19
import java.util.ArrayList;
20
import java.util.Arrays;
21
import java.util.List;
22
23
import org.jboss.arquillian.container.test.spi.TestRunner;
24
import org.jboss.arquillian.test.spi.TestResult;
25
import org.testng.TestNG;
26
import org.testng.internal.AnnotationTypeEnum;
27
import org.testng.xml.XmlClass;
28
import org.testng.xml.XmlInclude;
29
import org.testng.xml.XmlSuite;
30
import org.testng.xml.XmlTest;
37
38
public class TestNGTestRunner implements TestRunner
39
{
40
41
public TestResult execute(Class<?> testClass, String methodName)
42
43
TestListener resultListener = new TestListener();
44
45
TestNG runner = new TestNG(false);
46
runner.setVerbose(0);
47
48
runner.addListener(resultListener);
49
runner.addListener(new RemoveDependsOnTransformer());
50
runner.setXmlSuites(
51
Arrays.asList(createSuite(testClass, methodName)));
52
53
runner.run();
54
55
return resultListener.getTestResult();
56
}
57
58
private XmlSuite createSuite(Class<?> className, String methodName)
59
60
XmlSuite suite = new XmlSuite();
61
suite.setName("Arquillian");
62
suite.setAnnotations(AnnotationTypeEnum.JDK.getName());
63
64
XmlTest test = new XmlTest(suite);
65
test.setName("Arquillian - " + className);
66
List<XmlClass> testClasses = new ArrayList<XmlClass>();
67
XmlClass testClass = new XmlClass(className);
68
testClass.getIncludedMethods().add(new XmlInclude(methodName));
69
testClasses.add(testClass);
70
test.setXmlClasses(testClasses);
71
return suite;
72
73