Skip to content

Commit

Permalink
[#330] Improvement: Stabilize unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oomelianchuk committed Dec 17, 2024
1 parent 3d943ae commit 99666f4
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 169 deletions.
12 changes: 2 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>
com/xceptance/neodymium/junit4/tests/**/*Test.java</include>
</includes>
<includes>
<include>
com/xceptance/neodymium/util/**/*Test.java</include>
<include> com/xceptance/neodymium/junit4/tests/**/*Test.java</include>
<include> com/xceptance/neodymium/util/**/*Test.java</include>
</includes>
<excludes>
<exclude>
com/xceptance/neodymium/junit4/tests/visual/**/*Test.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/com/xceptance/neodymium/util/AllureAddons.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.InputStream;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
Expand Down Expand Up @@ -273,7 +274,14 @@ public static synchronized void addEnvironmentInformation(ImmutableMap<String, S
{
Selenide.sleep(100);
}
lock = FileChannel.open(Paths.get(getEnvFile().getAbsolutePath()), StandardOpenOption.APPEND).tryLock();
try
{
lock = FileChannel.open(Paths.get(getEnvFile().getAbsolutePath()), StandardOpenOption.APPEND).tryLock();
}
catch (OverlappingFileLockException e)
{
LOGGER.debug(getEnvFile() + " is already locked");
}
retries++;
}
while (retries < MAX_RETRY_COUNT && lock == null);
Expand Down Expand Up @@ -444,12 +452,13 @@ else if (key.equals(entry.getKey()))
{
LOGGER.warn("Could not acquire Filelock in time. Failed to add information about enviroment to Allure report");
}
}catch(ParserConfigurationException|TransformerException|SAXException|
}
catch (ParserConfigurationException | TransformerException | SAXException |

IOException e)
{
LOGGER.warn("Failed to add information about environment to Allure report", e);
}
IOException e)
{
LOGGER.warn("Failed to add information about environment to Allure report", e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import com.xceptance.neodymium.junit4.NeodymiumRunner;
import com.xceptance.neodymium.util.Neodymium;

//@Browser("Chrome_1024x768")
//@Browser("Chrome_1500x1000")
@Browser("Chrome_1024x768")
@Browser("Chrome_1500x1000")
@Browser("FF_1024x768")
@Browser("FF_1500x1000")
@RandomBrowsers(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit4.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.util.TestConfiguration;

Expand Down Expand Up @@ -42,9 +43,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackProxyErrorTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit4.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.util.TestConfiguration;

Expand Down Expand Up @@ -42,9 +43,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackProxyTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit4.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.util.TestConfiguration;

Expand All @@ -36,9 +37,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit5.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.junit5.tests.utils.NeodymiumTestExecutionSummary;
import com.xceptance.neodymium.util.TestConfiguration;
Expand Down Expand Up @@ -41,9 +42,14 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");

File tempConfigFile2 = File.createTempFile("BrowserstackProxyErrorTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit5.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.junit5.tests.utils.NeodymiumTestExecutionSummary;
import com.xceptance.neodymium.util.TestConfiguration;
Expand Down Expand Up @@ -41,9 +42,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackProxyTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit5.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.junit5.tests.utils.NeodymiumTestExecutionSummary;
import com.xceptance.neodymium.util.TestConfiguration;
Expand All @@ -24,7 +25,7 @@ public static void beforeClass() throws IOException
properties1.put("browserprofile.testEnvironment.browserstack.url", "https://hub-cloud.browserstack.com/wd/hub");
properties1.put("browserprofile.testEnvironment.browserstack.username", CONFIGURATION.browserstackUsername());
properties1.put("browserprofile.testEnvironment.browserstack.password", CONFIGURATION.browserstackAccessKey());

File tempConfigFile1 = new File("./config/credentials.properties");
writeMapToPropertiesFile(properties1, tempConfigFile1);
tempFiles.add(tempConfigFile1);
Expand All @@ -36,9 +37,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void TestAllureAddEnvironmentInformation() throws Exception

AllureAddons.addEnvironmentInformation(map6, EnvironmentInfoMode.ADD);
this.validateEnvironmentFile(expectedFileContentList);

// ignore value
ImmutableMap<String, String> map7 = ImmutableMap.<String, String> builder()
.put("d",
Expand Down Expand Up @@ -141,7 +141,7 @@ public void TestAllureAddEnvironmentInformation() throws Exception
private File getEnvFile()
{
File allureResultsDir = AllureAddons.getAllureResultsFolder();
return new File(allureResultsDir.getAbsoluteFile() + File.separator + "environment.xml");
return new File(allureResultsDir.getAbsoluteFile() + File.separator + "environment-test.xml");
}

private void validateEnvironmentFile(List<Entry<String, String>> list) throws Exception
Expand All @@ -151,10 +151,10 @@ private void validateEnvironmentFile(List<Entry<String, String>> list) throws Ex
Document doc = docBuilder.parse(getEnvFile());

Node environment = doc.getDocumentElement();
Assert.assertEquals("Wrong root node name in environments.xml", "environment", environment.getNodeName());
Assert.assertEquals("Wrong root node name in environments-test.xml", "environment-test", environment.getNodeName());

NodeList childNodes = environment.getChildNodes();
Assert.assertEquals("Wrong number of params in environments.xml", list.size(), childNodes.getLength());
Assert.assertEquals("Wrong number of params in environments-test.xml", list.size(), childNodes.getLength());

List<NameValuePair> params = new ArrayList<NameValuePair>();
for (int i = 0; i < childNodes.getLength(); i++)
Expand Down
Loading

0 comments on commit 99666f4

Please sign in to comment.