Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Create TestNG suite folder automatically
Browse files Browse the repository at this point in the history
Create given suite directory if it doesn't exist to improve user
experience.

#120

Signed-off-by: Dmytro Serdiuk <[email protected]>
  • Loading branch information
extsoft committed Aug 15, 2017
1 parent a8240ca commit c3df71f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@
* @version $Id$
* @since 0.1
*/
@SuppressWarnings("WeakerAccess")
public final class LoadableTestNGSuite implements TestNGSuite {

private final SunshineSuite artifacts;
private final Directory suitePath;

public LoadableTestNGSuite(FileSystem fileSystem, String suitePath, Condition filter) {
this(fileSystem, new DirectoryBase(suitePath), filter);
/**
* Construct new instance with the specified file system, suite's directory and tests filter.
* If suite's directory ({@code xmlSuiteDirectory}) doesn't exist, it will be created automatically.
*
* @param fileSystem the place with the tests
* @param xmlSuiteDirectory the place to store suite file
* @param filter the filter to be used to select desired tests
* @see #LoadableTestNGSuite(FileSystem, Directory, Condition)
* @since 0.2
*/
public LoadableTestNGSuite(FileSystem fileSystem, String xmlSuiteDirectory, Condition filter) {
this(
fileSystem,
new DirectoryWithAutomaticCreation(new DirectorySafe(new DirectoryBase(xmlSuiteDirectory))),
filter
);
}

public LoadableTestNGSuite(FileSystem fileSystem, Directory suitePath, Condition filter) {
Expand All @@ -37,12 +52,12 @@ public File tests() throws SuiteException {
XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setName("Sunshine suite");
try {
for (SunshineTest sunshineTest : artifacts.tests()) {
for (SunshineTest sunshineTest : this.artifacts.tests()) {
XmlTest test = new TestNGTest(sunshineTest).object();
test.setSuite(xmlSuite);
xmlSuite.addTest(test);
}
FileBase fileBase = new FileBase(suitePath, "sunshine-suite.xml");
FileBase fileBase = new FileBase(this.suitePath, "sunshine-suite.xml");
fileBase.write(xmlSuite.toXml());
return fileBase;
} catch (TestException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.tatools.sunshine.testng;

import io.github.tatools.sunshine.core.Condition.Fake;
import io.github.tatools.sunshine.core.SuiteException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import java.util.ArrayList;


/**
* @author Dmytro Serdiuk ([email protected])
* @version $Id$
* @since 0.2
*/
public class LoadableTestNGSuiteTest {

@Rule
public TemporaryFolder testFolder = new TemporaryFolder();

@Test
public void testAutomaticSuiteDirectoryCreation() throws SuiteException {
new LoadableTestNGSuite(
ArrayList::new,
this.testFolder.getRoot().getAbsolutePath() + "/custom",
new Fake(true)
).tests();
}
}

0 comments on commit c3df71f

Please sign in to comment.