From 93397a62a6aa3272844c5a6ca4fb8ee15b0df3ef Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Wed, 22 Jul 2020 16:30:02 +0200 Subject: [PATCH 01/18] #121 print stack trace --- .../xceptance/neodymium/tests/NeodymiumTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index b4fa781db..c0c04d309 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -14,6 +14,7 @@ import org.junit.Assert; import org.junit.runner.Description; import org.junit.runner.Result; +import org.junit.runner.notification.Failure; import com.google.common.base.Joiner; import com.xceptance.neodymium.NeodymiumRunner; @@ -54,11 +55,16 @@ public static void deleteTempFile(File tempFile) public void check(Result result, boolean expectedSuccessful, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, String expectedFailureMessage) { - Assert.assertEquals("Test successful", expectedSuccessful, result.wasSuccessful()); - Assert.assertEquals("Method run count", expectedRunCount, result.getRunCount()); - Assert.assertEquals("Method ignore count", expectedIgnoreCount, result.getIgnoreCount()); - Assert.assertEquals("Method fail count", expectedFailCount, result.getFailureCount()); - + String stackTrace = ""; + for (Failure failue : result.getFailures()) + { + stackTrace += failue.getTrace(); + } + Assert.assertEquals("Test successful " + (stackTrace.equals("") ? "" : "\nStack trace: " + stackTrace), expectedSuccessful, result.wasSuccessful()); + Assert.assertEquals("Method run count " + (stackTrace.equals("") ? "" : "\nStack trace: " + stackTrace), expectedRunCount, result.getRunCount()); + Assert.assertEquals("Method ignore count " + (stackTrace.equals("") ? "" : "\nStack trace: " + stackTrace), expectedIgnoreCount, + result.getIgnoreCount()); + Assert.assertEquals("Method fail count " + (stackTrace.equals("") ? "" : "\nStack trace: " + stackTrace), expectedFailCount, result.getFailureCount()); if (expectedFailureMessage != null) { Assert.assertTrue("Failure count", expectedFailCount == 1); From eeed6fbf8d31f67d666b3cd5ba7a769d5ca4ebbb Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Tue, 28 Jul 2020 14:47:04 +0200 Subject: [PATCH 02/18] add documentation and test for checkPass and checkFail methods --- .../neodymium/tests/NeodymiumTest.java | 49 +++++-- .../neodymium/tests/NeodymiumTestTest.java | 125 ++++++++++++++++++ 2 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index c0c04d309..521ed7d54 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -60,23 +60,56 @@ public void check(Result result, boolean expectedSuccessful, int expectedRunCoun { stackTrace += failue.getTrace(); } - Assert.assertEquals("Test successful " + (stackTrace.equals("") ? "" : "\nStack trace: " + stackTrace), expectedSuccessful, result.wasSuccessful()); - Assert.assertEquals("Method run count " + (stackTrace.equals("") ? "" : "\nStack trace: " + stackTrace), expectedRunCount, result.getRunCount()); - Assert.assertEquals("Method ignore count " + (stackTrace.equals("") ? "" : "\nStack trace: " + stackTrace), expectedIgnoreCount, - result.getIgnoreCount()); - Assert.assertEquals("Method fail count " + (stackTrace.equals("") ? "" : "\nStack trace: " + stackTrace), expectedFailCount, result.getFailureCount()); - if (expectedFailureMessage != null) + try + { + Assert.assertEquals("Test successful", expectedSuccessful, result.wasSuccessful()); + Assert.assertEquals("Method run count", expectedRunCount, result.getRunCount()); + Assert.assertEquals("Method ignore count", expectedIgnoreCount, result.getIgnoreCount()); + Assert.assertEquals("Method fail count", expectedFailCount, result.getFailureCount()); + if (expectedFailureMessage != null) + { + Assert.assertTrue("Failure count", expectedFailCount == 1); + Assert.assertEquals("Failure message", expectedFailureMessage, result.getFailures().get(0).getMessage()); + } + } + catch (AssertionError e) { - Assert.assertTrue("Failure count", expectedFailCount == 1); - Assert.assertEquals("Failure message", expectedFailureMessage, result.getFailures().get(0).getMessage()); + throw new RuntimeException("Assertion failed. " + e.getMessage() + " Stack trace: " + stackTrace, e); } } + /** + * Assert all tests in run were successful + * + * @param result + * test result to make assertions on + * @param expectedRunCount + * expected number of run tests (including ignored) + * @param expectedIgnoreCount + * expected number of ignored tests + * @param expectedFailCount + * expected number of failed tests (always 0, otherwise assertion will fail) + */ + // FIXME: remove expectedFailCount parameter and replace it with 0 public void checkPass(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount) { check(result, true, expectedRunCount, expectedIgnoreCount, expectedFailCount, null); } + /** + * Assert the are one or more failed tests in run + * + * @param result + * test result to make assertions on + * @param expectedRunCount + * expected number of run tests (including ignored) + * @param expectedIgnoreCount + * expected number of ignored tests + * @param expectedFailCount + * expected number of failed tests + * @param expectedFailureMessage + * expected failure message (only possible to assert if expectedFailCount is equals 1) + */ public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, String expectedFailureMessage) { diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java new file mode 100644 index 000000000..ab5feb752 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java @@ -0,0 +1,125 @@ +package com.xceptance.neodymium.tests; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; +import org.junit.runner.Description; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; + +public class NeodymiumTestTest extends NeodymiumTest +{ + @Rule + public TestName name = new TestName(); + + @Test + public void testCheckFailedOneFromOne() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + final String errorMessage = "This is RuntimeException 1"; + Result result = createResult(1, 0, new ArrayList() + { + { + this.add(new RuntimeException(errorMessage)); + } + }); + checkFail(result, 1, 0, 1, errorMessage); + } + + @Test + public void testCheckFailedOneFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + final String errorMessage = "This is RuntimeException 1"; + Result result = createResult(2, 0, new ArrayList() + { + { + this.add(new RuntimeException(errorMessage)); + } + }); + checkFail(result, 2, 0, 1, errorMessage); + } + + @Test + public void testCheckFailedTwoFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + Result result = createResult(2, 0, new ArrayList() + { + { + this.add(new RuntimeException("This is RuntimeException 1")); + this.add(new RuntimeException("This is RuntimeException 2")); + } + }); + + // no assertion for failure message, as one is only possible for single fail + checkFail(result, 2, 0, 2, null); + } + + @Test + public void testCheckOneFailedOneIgnoredFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + final String errorMessage = "This is RuntimeException 1"; + Result result = createResult(2, 1, new ArrayList() + { + { + this.add(new RuntimeException(errorMessage)); + } + }); + checkFail(result, 2, 1, 1, errorMessage); + } + + // ------ checkPass----------- + @Test + public void testCheckPassedOneFromOne() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + Result result = createResult(1, 0, new ArrayList()); + checkPass(result, 1, 0, 0); + } + + @Test + public void testCheckPassedTwoFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + Result result = createResult(2, 0, new ArrayList()); + checkPass(result, 2, 0, 0); + } + + @Test + public void testCheckOnePassedOneIgnoredFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + Result result = createResult(2, 1, new ArrayList()); + checkPass(result, 2, 1, 0); + } + + private Result createResult(int runCount, int ignoreCount, List failureCauses) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + Result result = new Result(); + Field countField = Result.class.getDeclaredField("count"); + Field ignoreCountField = Result.class.getDeclaredField("ignoreCount"); + Field failuresField = Result.class.getDeclaredField("failures"); + + countField.setAccessible(true); + ignoreCountField.setAccessible(true); + failuresField.setAccessible(true); + + countField.set(result, new AtomicInteger(runCount)); + ignoreCountField.set(result, new AtomicInteger(ignoreCount)); + + CopyOnWriteArrayList failures = new CopyOnWriteArrayList<>(); + for (Throwable failureCause : failureCauses) + { + Failure failure = new Failure(Description.createTestDescription(getClass(), name.getMethodName()), failureCause); + failures.add(failure); + } + failuresField.set(result, failures); + + countField.setAccessible(false); + ignoreCountField.setAccessible(false); + failuresField.setAccessible(false); + return result; + } +} From 49c58857db8d48988d5d6abc4674d280122fcc07 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Wed, 29 Jul 2020 10:18:09 +0200 Subject: [PATCH 03/18] remove expectedFailCount parameter from checkPass and replace with 0 --- .../tests/AllureSelenideListenerTest.java | 4 +-- .../neodymium/tests/CucumberTest.java | 4 +-- .../neodymium/tests/DataUtilsTest.java | 4 +-- ...nvironmentAndBrowserConfigurationTest.java | 4 +-- .../neodymium/tests/NeodymiumContextTest.java | 16 ++++++------ .../neodymium/tests/NeodymiumTest.java | 7 ++--- .../neodymium/tests/NeodymiumTestTest.java | 6 ++--- .../tests/NeodymiumWebDriverTest.java | 16 ++++++------ .../tests/ParameterStatementTest.java | 8 +++--- .../tests/ProxyConfigurationTest.java | 4 +-- .../tests/TestDataStatementTest.java | 26 +++++++++---------- 11 files changed, 48 insertions(+), 51 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/AllureSelenideListenerTest.java b/src/test/java/com/xceptance/neodymium/tests/AllureSelenideListenerTest.java index 2e99b5805..6a8dac3b6 100644 --- a/src/test/java/com/xceptance/neodymium/tests/AllureSelenideListenerTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/AllureSelenideListenerTest.java @@ -13,13 +13,13 @@ public class AllureSelenideListenerTest extends NeodymiumTest public void testAllureSelenideListenerIsActiveForCucumber() { Result result = JUnitCore.runClasses(CucumberValidateAllureSelenideListenerIsActive.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test public void testAllureSelenideListenerIsActiveForJava() { Result result = JUnitCore.runClasses(AllureSelenideListenerIsActiveForJava.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java b/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java index 381ea4bf6..a3b872842 100644 --- a/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java @@ -15,7 +15,7 @@ public class CucumberTest extends NeodymiumTest public void testSetBrowserViaTestData() throws Exception { Result result = JUnitCore.runClasses(CucumberSetBrowserViaTestData.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -29,7 +29,7 @@ public void testSetBrowserViaTestDataFail() throws Exception public void testSetBrowserViaTag() throws Exception { Result result = JUnitCore.runClasses(CucumberSetBrowserViaTag.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test diff --git a/src/test/java/com/xceptance/neodymium/tests/DataUtilsTest.java b/src/test/java/com/xceptance/neodymium/tests/DataUtilsTest.java index f5df55203..d840caf23 100644 --- a/src/test/java/com/xceptance/neodymium/tests/DataUtilsTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/DataUtilsTest.java @@ -14,7 +14,7 @@ public void testDataUtils() throws Exception { // test the data utils Result result = JUnitCore.runClasses(DataUtilsTests.class); - checkPass(result, 9, 0, 0); + checkPass(result, 9, 0); } @Test @@ -22,6 +22,6 @@ public void testDataUtilsXml() throws Exception { // test the data utils Result result = JUnitCore.runClasses(DataUtilsTestsXml.class); - checkPass(result, 9, 0, 0); + checkPass(result, 9, 0); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/EnvironmentAndBrowserConfigurationTest.java b/src/test/java/com/xceptance/neodymium/tests/EnvironmentAndBrowserConfigurationTest.java index b53abfc0f..541153cbd 100644 --- a/src/test/java/com/xceptance/neodymium/tests/EnvironmentAndBrowserConfigurationTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/EnvironmentAndBrowserConfigurationTest.java @@ -101,7 +101,7 @@ public void testOverridingEnvironmentsAndBrowsers() { // test environment configuration Result result = JUnitCore.runClasses(EnvironmentAndBrowserConfiguration.class); - checkPass(result, 5, 0, 0); + checkPass(result, 5, 0); } @Test @@ -109,7 +109,7 @@ public void testConfigureBadEnvironmentProxies() { // test environment configuration Result result = JUnitCore.runClasses(BadProxyEnvironmentConfiguration.class); - checkPass(result, 3, 0, 0); + checkPass(result, 3, 0); } @Test diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumContextTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumContextTest.java index 36d0d1afa..ea759de01 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumContextTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumContextTest.java @@ -50,7 +50,7 @@ public void testIsSite() { // test the isSite function Result result = JUnitCore.runClasses(IsSiteTests.class); - checkPass(result, 10, 0, 0); + checkPass(result, 10, 0); } @Test @@ -58,7 +58,7 @@ public void testContextGetCleared() throws Exception { // test that NeodymiumRunner clears the context before each run Result result = JUnitCore.runClasses(ContextGetsCleared.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test @@ -66,35 +66,35 @@ public void testCucumberContextGetsCleared() throws Exception { // test that NeodymiumCucumberRunListener clears the context before each run Result result = JUnitCore.runClasses(CucumberContextGetsCleared.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test public void testBrowserContextSetup() throws Exception { Result result = JUnitCore.runClasses(BrowserContextSetup.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test public void testDefaultSelenideConfigurationCheck() throws Exception { Result result = JUnitCore.runClasses(DefaultSelenideConfiguration.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test public void testSelenideConfigurationShortcuts() throws Exception { Result result = JUnitCore.runClasses(SelenideConfigurationShortcuts.class); - checkPass(result, 4, 0, 0); + checkPass(result, 4, 0); } @Test public void testOverridingNeodymiumConfiguration() throws Exception { Result result = JUnitCore.runClasses(OverrideNeodymiumConfiguration.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test @@ -137,6 +137,6 @@ public void testContextWindowSize() throws Exception // checks Neodymium functions for different browser sizes Result result = JUnitCore.runClasses(WindowSizeTests.class); - checkPass(result, 5, 0, 0); + checkPass(result, 5, 0); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 521ed7d54..583873729 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -87,13 +87,10 @@ public void check(Result result, boolean expectedSuccessful, int expectedRunCoun * expected number of run tests (including ignored) * @param expectedIgnoreCount * expected number of ignored tests - * @param expectedFailCount - * expected number of failed tests (always 0, otherwise assertion will fail) */ - // FIXME: remove expectedFailCount parameter and replace it with 0 - public void checkPass(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount) + public void checkPass(Result result, int expectedRunCount, int expectedIgnoreCount) { - check(result, true, expectedRunCount, expectedIgnoreCount, expectedFailCount, null); + check(result, true, expectedRunCount, expectedIgnoreCount, 0, null); } /** diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java index ab5feb752..befccd788 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java @@ -77,21 +77,21 @@ public void testCheckOneFailedOneIgnoredFromTwo() throws NoSuchFieldException, S public void testCheckPassedOneFromOne() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Result result = createResult(1, 0, new ArrayList()); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test public void testCheckPassedTwoFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Result result = createResult(2, 0, new ArrayList()); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test public void testCheckOnePassedOneIgnoredFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Result result = createResult(2, 1, new ArrayList()); - checkPass(result, 2, 1, 0); + checkPass(result, 2, 1); } private Result createResult(int runCount, int ignoreCount, List failureCauses) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java index a72c75506..efd3f0125 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java @@ -27,7 +27,7 @@ public class NeodymiumWebDriverTest extends NeodymiumTest public void testValidateWebDriverClosed() { Result result = JUnitCore.runClasses(ValidateWebDriverClosed.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test @@ -35,7 +35,7 @@ public void testValidateReuseWebDriver() { // XVFB or a display needed Result result = JUnitCore.runClasses(ValidateReuseWebDriver.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test @@ -43,7 +43,7 @@ public void testValidateClearReuseWebDriverCache() { // XVFB or a display needed Result result = JUnitCore.runClasses(ValidateClearReuseWebDriverCache.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test @@ -51,14 +51,14 @@ public void testValidatePreventReuseWebDriver() { // XVFB or a display needed Result result = JUnitCore.runClasses(ValidatePreventReuseWebDriver.class); - checkPass(result, 3, 0, 0); + checkPass(result, 3, 0); } @Test public void testValidateKeepWebDriverOpen() { Result result = JUnitCore.runClasses(ValidateKeepWebDriverOpen.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test @@ -72,21 +72,21 @@ public void testValidateKeepWebDriverOpenOnFailure() public void testLocalProxyTrustAllServers() { Result result = JUnitCore.runClasses(LocalProxyTrustAllServers.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test public void testLocalProxyUsingSelfCreatedCertificates() { Result result = JUnitCore.runClasses(LocalProxyUsingSelfCreatedCertificates.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test public void testLocalProxyUsingProvidedCertificates() { Result result = JUnitCore.runClasses(LocalProxyUsingProvidedCertificates.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test diff --git a/src/test/java/com/xceptance/neodymium/tests/ParameterStatementTest.java b/src/test/java/com/xceptance/neodymium/tests/ParameterStatementTest.java index 3c0706f9a..bfcc632ff 100644 --- a/src/test/java/com/xceptance/neodymium/tests/ParameterStatementTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/ParameterStatementTest.java @@ -25,7 +25,7 @@ public void testParameterFieldWithoutGenerator() { // test parameter annotated class members without an generator function (@Parameters) Result result = JUnitCore.runClasses(ParameterFieldButNoGenerator.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -60,7 +60,7 @@ public void testGeneratorIterableReturnOne() { // one test data element, one test iteration Result result = JUnitCore.runClasses(GeneratorIterableReturnOne.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -84,7 +84,7 @@ public void testGeneratorAutoTypeConversion() { // test auto type conversion from string to various data types, as well as arbitrary type injection Result result = JUnitCore.runClasses(GeneratorAutoTypeConversion.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -101,7 +101,7 @@ public void testGeneratorCanSetStaticField() { // test that a static field can be set Result result = JUnitCore.runClasses(GeneratorCanSetStaticField.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test diff --git a/src/test/java/com/xceptance/neodymium/tests/ProxyConfigurationTest.java b/src/test/java/com/xceptance/neodymium/tests/ProxyConfigurationTest.java index 70a92177c..15d4b69af 100644 --- a/src/test/java/com/xceptance/neodymium/tests/ProxyConfigurationTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/ProxyConfigurationTest.java @@ -59,7 +59,7 @@ public void testExecutionWithProxy() { // test proxy configuration as far as possible without setting up a proxy Result result = JUnitCore.runClasses(RunWithProxy.class); - checkPass(result, 2, 0, 0); + checkPass(result, 2, 0); } @Test @@ -67,6 +67,6 @@ public void testSettingOfProxyForWebdriver() { // test adding proxy configuration to different WebDriver options and validate them Result result = JUnitCore.runClasses(SetProxyForWebDriver.class); - checkPass(result, 4, 0, 0); + checkPass(result, 4, 0); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/TestDataStatementTest.java b/src/test/java/com/xceptance/neodymium/tests/TestDataStatementTest.java index 363005bc5..87e4e6c0a 100644 --- a/src/test/java/com/xceptance/neodymium/tests/TestDataStatementTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/TestDataStatementTest.java @@ -51,7 +51,7 @@ public void testCanReadPackageDataCSV() { // test package test data csv is read Result result = JUnitCore.runClasses(CanReadPackageDataCSV.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -59,7 +59,7 @@ public void testCanReadPackageDataJson() { // test package test data json is read Result result = JUnitCore.runClasses(CanReadPackageDataJson.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -67,7 +67,7 @@ public void testCanReadPackageDataProperties() { // test package test data properties is read Result result = JUnitCore.runClasses(CanReadPackageDataProperties.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -75,7 +75,7 @@ public void testCanReadPackageDataXML() { // test package test data xml is read Result result = JUnitCore.runClasses(CanReadPackageDataXML.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -83,7 +83,7 @@ public void testCanReadDataSetCSV() { // test data set csv is read Result result = JUnitCore.runClasses(CanReadDataSetCSV.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -91,7 +91,7 @@ public void testCanReadDataSetJson() { // test data set json is read Result result = JUnitCore.runClasses(CanReadDataSetJson.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -99,7 +99,7 @@ public void testCanReadDataSetXML() { // test data set xml is read Result result = JUnitCore.runClasses(CanReadDataSetXML.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -107,7 +107,7 @@ public void testPackageTestDataInheritance() { // test inheritance of package test data Result result = JUnitCore.runClasses(PackageTestDataInheritance.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -115,7 +115,7 @@ public void testGrandChildPackageTestDataInheritance() { // test multiple inheritance of package test data Result result = JUnitCore.runClasses(GrandChildPackageTestDataInheritance.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -123,7 +123,7 @@ public void testDataSetOverridesPackageData() { // test that data set overrides package test data Result result = JUnitCore.runClasses(DataSetOverridesPackageData.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test @@ -131,7 +131,7 @@ public void testDuplicateTestId() throws Exception { // more than one entry with the same "testId" Result result = JUnitCore.runClasses(DuplicateTestId.class); - checkPass(result, 6, 0, 0); + checkPass(result, 6, 0); } @Test @@ -140,7 +140,7 @@ public void testSpecialCharacterTestId() throws Throwable // special characters in testId // parenthesis will be converted to to brackets Result result = JUnitCore.runClasses(SpecialCharacterTestId.class); - checkPass(result, 7, 0, 0); + checkPass(result, 7, 0); } /////////////////////// @@ -364,7 +364,7 @@ public void testDataFileAnnotation() throws Exception { // test package test data csv is read Result result = JUnitCore.runClasses(com.xceptance.neodymium.testclasses.data.file.json.CanReadDataSetJson.class); - checkPass(result, 1, 0, 0); + checkPass(result, 1, 0); } @Test From 747a374488b7d97e525be6a92aee7b2cc3461693 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 31 Jul 2020 11:21:48 +0200 Subject: [PATCH 04/18] split checkFail into 3 methods and test them --- .../neodymium/tests/CucumberTest.java | 4 +- .../neodymium/tests/NeodymiumTest.java | 55 ++++++++++-- .../neodymium/tests/NeodymiumTestTest.java | 84 ++++++++++++++----- .../tests/NeodymiumWebDriverTest.java | 2 +- .../neodymium/tests/SoftAssertionTest.java | 2 +- 5 files changed, 114 insertions(+), 33 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java b/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java index a3b872842..e5d65359f 100644 --- a/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/CucumberTest.java @@ -22,7 +22,7 @@ public void testSetBrowserViaTestData() throws Exception public void testSetBrowserViaTestDataFail() throws Exception { Result result = JUnitCore.runClasses(CucumberSetBrowserViaTestDataFail.class); - checkFail(result, 1, 0, 1, null); + checkFail(result, 1, 0, 1); } @Test @@ -36,6 +36,6 @@ public void testSetBrowserViaTag() throws Exception public void testSetBrowserViaTagFail() throws Exception { Result result = JUnitCore.runClasses(CucumberSetBrowserViaTagFail.class); - checkFail(result, 1, 0, 1, null); + checkFail(result, 1, 0, 1); } } diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 583873729..e892eea6d 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -6,6 +6,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -53,7 +54,7 @@ public static void deleteTempFile(File tempFile) } public void check(Result result, boolean expectedSuccessful, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, - String expectedFailureMessage) + Map expectedFailureMessages) { String stackTrace = ""; for (Failure failue : result.getFailures()) @@ -66,10 +67,10 @@ public void check(Result result, boolean expectedSuccessful, int expectedRunCoun Assert.assertEquals("Method run count", expectedRunCount, result.getRunCount()); Assert.assertEquals("Method ignore count", expectedIgnoreCount, result.getIgnoreCount()); Assert.assertEquals("Method fail count", expectedFailCount, result.getFailureCount()); - if (expectedFailureMessage != null) + for (int i = 0; expectedFailureMessages != null && i < result.getFailures().size(); i++) { - Assert.assertTrue("Failure count", expectedFailCount == 1); - Assert.assertEquals("Failure message", expectedFailureMessage, result.getFailures().get(0).getMessage()); + String methodName = result.getFailures().get(i).getDescription().getMethodName(); + Assert.assertEquals("Failure message", expectedFailureMessages.get(methodName), result.getFailures().get(i).getMessage()); } } catch (AssertionError e) @@ -93,6 +94,23 @@ public void checkPass(Result result, int expectedRunCount, int expectedIgnoreCou check(result, true, expectedRunCount, expectedIgnoreCount, 0, null); } + /** + * Assert the are one or more failed tests in run + * + * @param result + * test result to make assertions on + * @param expectedRunCount + * expected number of run tests (including ignored) + * @param expectedIgnoreCount + * expected number of ignored tests + * @param expectedFailCount + * expected number of failed tests + */ + public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount) + { + check(result, false, expectedRunCount, expectedIgnoreCount, expectedFailCount, null); + } + /** * Assert the are one or more failed tests in run * @@ -105,12 +123,37 @@ public void checkPass(Result result, int expectedRunCount, int expectedIgnoreCou * @param expectedFailCount * expected number of failed tests * @param expectedFailureMessage - * expected failure message (only possible to assert if expectedFailCount is equals 1) + * expected failure message for all failures */ public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, String expectedFailureMessage) { - check(result, false, expectedRunCount, expectedIgnoreCount, expectedFailCount, expectedFailureMessage); + HashMap expectedFailureMessages = new HashMap(); + for (Failure failure : result.getFailures()) + { + expectedFailureMessages.put(failure.getDescription().getMethodName(), expectedFailureMessage); + } + check(result, false, expectedRunCount, expectedIgnoreCount, expectedFailCount, expectedFailureMessages); + } + + /** + * Assert the are one or more failed tests in run + * + * @param result + * test result to make assertions on + * @param expectedRunCount + * expected number of run tests (including ignored) + * @param expectedIgnoreCount + * expected number of ignored tests + * @param expectedFailCount + * expected number of failed tests + * @param expectedFailureMessages + * Map with test method name as key and corresponding expected failure message as value + */ + public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, + Map expectedFailureMessages) + { + check(result, false, expectedRunCount, expectedIgnoreCount, expectedFailCount, expectedFailureMessages); } public void checkDescription(Description testDescription, String[] expectedTestDescription) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java index befccd788..0bac1e138 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java @@ -1,8 +1,8 @@ package com.xceptance.neodymium.tests; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicInteger; @@ -22,10 +22,10 @@ public class NeodymiumTestTest extends NeodymiumTest public void testCheckFailedOneFromOne() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - Result result = createResult(1, 0, new ArrayList() + Result result = createResult(1, 0, new HashMap() { { - this.add(new RuntimeException(errorMessage)); + this.put(name.getMethodName() + "1", new RuntimeException(errorMessage)); } }); checkFail(result, 1, 0, 1, errorMessage); @@ -35,38 +35,74 @@ public void testCheckFailedOneFromOne() throws NoSuchFieldException, SecurityExc public void testCheckFailedOneFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - Result result = createResult(2, 0, new ArrayList() + Result result = createResult(2, 0, new HashMap() { { - this.add(new RuntimeException(errorMessage)); + this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); } }); checkFail(result, 2, 0, 1, errorMessage); } @Test - public void testCheckFailedTwoFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + public void testCheckFailedTwoFromTwoNumber() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(2, 0, new ArrayList() + Result result = createResult(2, 0, new HashMap() { { - this.add(new RuntimeException("This is RuntimeException 1")); - this.add(new RuntimeException("This is RuntimeException 2")); + this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); + this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 1")); } }); // no assertion for failure message, as one is only possible for single fail - checkFail(result, 2, 0, 2, null); + checkFail(result, 2, 0, 2); + } + + @Test + public void testCheckFailedTwoFromTwoOneFailureMessage() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + Result result = createResult(2, 0, new HashMap() + { + { + this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); + this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 1")); + } + }); + + // no assertion for failure message, as one is only possible for single fail + checkFail(result, 2, 0, 2, "This is RuntimeException 1"); + } + + @Test + public void testCheckFailedTwoFromTwoTwoFailureMessages() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException + { + Result result = createResult(2, 0, new HashMap() + { + { + this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); + this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 2")); + } + }); + HashMap expectedFailureMessages = new HashMap() + { + { + this.put(name.getMethodName() + "1", "This is RuntimeException 1"); + this.put(name.getMethodName() + "2", "This is RuntimeException 2"); + } + }; + // no assertion for failure message, as one is only possible for single fail + checkFail(result, 2, 0, 2, expectedFailureMessages); } @Test public void testCheckOneFailedOneIgnoredFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - Result result = createResult(2, 1, new ArrayList() + Result result = createResult(2, 1, new HashMap() { { - this.add(new RuntimeException(errorMessage)); + this.put(name.getMethodName() + "1", new RuntimeException(errorMessage)); } }); checkFail(result, 2, 1, 1, errorMessage); @@ -76,25 +112,25 @@ public void testCheckOneFailedOneIgnoredFromTwo() throws NoSuchFieldException, S @Test public void testCheckPassedOneFromOne() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(1, 0, new ArrayList()); + Result result = createResult(1, 0, null); checkPass(result, 1, 0); } @Test public void testCheckPassedTwoFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(2, 0, new ArrayList()); + Result result = createResult(2, 0, null); checkPass(result, 2, 0); } @Test public void testCheckOnePassedOneIgnoredFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(2, 1, new ArrayList()); + Result result = createResult(2, 1, null); checkPass(result, 2, 1); } - private Result createResult(int runCount, int ignoreCount, List failureCauses) + private Result createResult(int runCount, int ignoreCount, Map failureCauses) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Result result = new Result(); @@ -109,14 +145,16 @@ private Result createResult(int runCount, int ignoreCount, List failu countField.set(result, new AtomicInteger(runCount)); ignoreCountField.set(result, new AtomicInteger(ignoreCount)); - CopyOnWriteArrayList failures = new CopyOnWriteArrayList<>(); - for (Throwable failureCause : failureCauses) + if (failureCauses != null) { - Failure failure = new Failure(Description.createTestDescription(getClass(), name.getMethodName()), failureCause); - failures.add(failure); + CopyOnWriteArrayList failures = new CopyOnWriteArrayList<>(); + for (String testMethodName : failureCauses.keySet()) + { + Failure failure = new Failure(Description.createTestDescription(getClass(), testMethodName), failureCauses.get(testMethodName)); + failures.add(failure); + } + failuresField.set(result, failures); } - failuresField.set(result, failures); - countField.setAccessible(false); ignoreCountField.setAccessible(false); failuresField.setAccessible(false); diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java index efd3f0125..0f6fd3892 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumWebDriverTest.java @@ -65,7 +65,7 @@ public void testValidateKeepWebDriverOpen() public void testValidateKeepWebDriverOpenOnFailure() { Result result = JUnitCore.runClasses(ValidateKeepWebDriverOpenOnFailure.class); - checkFail(result, 3, 0, 1, null); + checkFail(result, 3, 0, 1); } @Test diff --git a/src/test/java/com/xceptance/neodymium/tests/SoftAssertionTest.java b/src/test/java/com/xceptance/neodymium/tests/SoftAssertionTest.java index f8f279463..6ba84b11c 100644 --- a/src/test/java/com/xceptance/neodymium/tests/SoftAssertionTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/SoftAssertionTest.java @@ -12,6 +12,6 @@ public class SoftAssertionTest extends NeodymiumTest public void validateSoftAssertion() { Result result = JUnitCore.runClasses(UseSoftAssertions.class); - checkFail(result, 1, 0, 1, null); + checkFail(result, 1, 0, 1); } } From 318b84d0fcc471a2fcbc47e865d67b3bfd1eba23 Mon Sep 17 00:00:00 2001 From: Marcel Pfotenhauer Date: Thu, 27 Aug 2020 14:51:48 +0200 Subject: [PATCH 05/18] removed warnings --- .../neodymium/tests/NeodymiumTestTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java index 0bac1e138..07eaa3b59 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java @@ -24,6 +24,8 @@ public void testCheckFailedOneFromOne() throws NoSuchFieldException, SecurityExc final String errorMessage = "This is RuntimeException 1"; Result result = createResult(1, 0, new HashMap() { + private static final long serialVersionUID = 1L; + { this.put(name.getMethodName() + "1", new RuntimeException(errorMessage)); } @@ -37,6 +39,8 @@ public void testCheckFailedOneFromTwo() throws NoSuchFieldException, SecurityExc final String errorMessage = "This is RuntimeException 1"; Result result = createResult(2, 0, new HashMap() { + private static final long serialVersionUID = 2L; + { this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); } @@ -49,6 +53,8 @@ public void testCheckFailedTwoFromTwoNumber() throws NoSuchFieldException, Secur { Result result = createResult(2, 0, new HashMap() { + private static final long serialVersionUID = 3L; + { this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 1")); @@ -64,6 +70,8 @@ public void testCheckFailedTwoFromTwoOneFailureMessage() throws NoSuchFieldExcep { Result result = createResult(2, 0, new HashMap() { + private static final long serialVersionUID = 4L; + { this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 1")); @@ -79,6 +87,8 @@ public void testCheckFailedTwoFromTwoTwoFailureMessages() throws NoSuchFieldExce { Result result = createResult(2, 0, new HashMap() { + private static final long serialVersionUID = 5L; + { this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 2")); @@ -86,6 +96,8 @@ public void testCheckFailedTwoFromTwoTwoFailureMessages() throws NoSuchFieldExce }); HashMap expectedFailureMessages = new HashMap() { + private static final long serialVersionUID = 6L; + { this.put(name.getMethodName() + "1", "This is RuntimeException 1"); this.put(name.getMethodName() + "2", "This is RuntimeException 2"); @@ -101,6 +113,8 @@ public void testCheckOneFailedOneIgnoredFromTwo() throws NoSuchFieldException, S final String errorMessage = "This is RuntimeException 1"; Result result = createResult(2, 1, new HashMap() { + private static final long serialVersionUID = 7L; + { this.put(name.getMethodName() + "1", new RuntimeException(errorMessage)); } From f94d3339d215d7db9c1f7665f4d2e1aaa373b289 Mon Sep 17 00:00:00 2001 From: Marcel Pfotenhauer Date: Thu, 27 Aug 2020 14:52:58 +0200 Subject: [PATCH 06/18] #121: change naming --- .../{NeodymiumTestTest.java => NeodymiumTestSelfTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/com/xceptance/neodymium/tests/{NeodymiumTestTest.java => NeodymiumTestSelfTest.java} (99%) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java similarity index 99% rename from src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java rename to src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java index 07eaa3b59..9b6843e9e 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java @@ -13,7 +13,7 @@ import org.junit.runner.Result; import org.junit.runner.notification.Failure; -public class NeodymiumTestTest extends NeodymiumTest +public class NeodymiumTestSelfTest extends NeodymiumTest { @Rule public TestName name = new TestName(); From e0ed3b73f928d7478c4d9fae2fa315259e737f45 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 28 Aug 2020 14:59:50 +0200 Subject: [PATCH 07/18] used stream to parse stack trace to String --- .../java/com/xceptance/neodymium/tests/NeodymiumTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 8af6a7512..2db7952a7 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -10,6 +10,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import org.junit.AfterClass; @@ -56,11 +57,8 @@ public static void deleteTempFile(File tempFile) public void check(Result result, boolean expectedSuccessful, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, Map expectedFailureMessages) { - String stackTrace = ""; - for (Failure failue : result.getFailures()) - { - stackTrace += failue.getTrace(); - } + final Optional accumulatedTrace = result.getFailures().stream().map(Failure::getTrace).reduce(String::concat); + final String stackTrace = accumulatedTrace.orElse("n/a"); try { Assert.assertEquals("Test successful", expectedSuccessful, result.wasSuccessful()); From fffaf861a3855d5345e5c2dc4eabc522a6e2fc13 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 28 Aug 2020 15:32:09 +0200 Subject: [PATCH 08/18] all variables in NeodymiumTestSelfTest made to final --- .../tests/NeodymiumTestSelfTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java index 9b6843e9e..d7c1f8e3c 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java @@ -22,7 +22,7 @@ public class NeodymiumTestSelfTest extends NeodymiumTest public void testCheckFailedOneFromOne() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - Result result = createResult(1, 0, new HashMap() + final Result result = createResult(1, 0, new HashMap() { private static final long serialVersionUID = 1L; @@ -37,7 +37,7 @@ public void testCheckFailedOneFromOne() throws NoSuchFieldException, SecurityExc public void testCheckFailedOneFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - Result result = createResult(2, 0, new HashMap() + final Result result = createResult(2, 0, new HashMap() { private static final long serialVersionUID = 2L; @@ -51,7 +51,7 @@ public void testCheckFailedOneFromTwo() throws NoSuchFieldException, SecurityExc @Test public void testCheckFailedTwoFromTwoNumber() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(2, 0, new HashMap() + final Result result = createResult(2, 0, new HashMap() { private static final long serialVersionUID = 3L; @@ -68,7 +68,7 @@ public void testCheckFailedTwoFromTwoNumber() throws NoSuchFieldException, Secur @Test public void testCheckFailedTwoFromTwoOneFailureMessage() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(2, 0, new HashMap() + final Result result = createResult(2, 0, new HashMap() { private static final long serialVersionUID = 4L; @@ -85,7 +85,7 @@ public void testCheckFailedTwoFromTwoOneFailureMessage() throws NoSuchFieldExcep @Test public void testCheckFailedTwoFromTwoTwoFailureMessages() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(2, 0, new HashMap() + final Result result = createResult(2, 0, new HashMap() { private static final long serialVersionUID = 5L; @@ -94,7 +94,7 @@ public void testCheckFailedTwoFromTwoTwoFailureMessages() throws NoSuchFieldExce this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 2")); } }); - HashMap expectedFailureMessages = new HashMap() + final HashMap expectedFailureMessages = new HashMap() { private static final long serialVersionUID = 6L; @@ -111,7 +111,7 @@ public void testCheckFailedTwoFromTwoTwoFailureMessages() throws NoSuchFieldExce public void testCheckOneFailedOneIgnoredFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - Result result = createResult(2, 1, new HashMap() + final Result result = createResult(2, 1, new HashMap() { private static final long serialVersionUID = 7L; @@ -126,31 +126,31 @@ public void testCheckOneFailedOneIgnoredFromTwo() throws NoSuchFieldException, S @Test public void testCheckPassedOneFromOne() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(1, 0, null); + final Result result = createResult(1, 0, null); checkPass(result, 1, 0); } @Test public void testCheckPassedTwoFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(2, 0, null); + final Result result = createResult(2, 0, null); checkPass(result, 2, 0); } @Test public void testCheckOnePassedOneIgnoredFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = createResult(2, 1, null); + final Result result = createResult(2, 1, null); checkPass(result, 2, 1); } private Result createResult(int runCount, int ignoreCount, Map failureCauses) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Result result = new Result(); - Field countField = Result.class.getDeclaredField("count"); - Field ignoreCountField = Result.class.getDeclaredField("ignoreCount"); - Field failuresField = Result.class.getDeclaredField("failures"); + final Result result = new Result(); + final Field countField = Result.class.getDeclaredField("count"); + final Field ignoreCountField = Result.class.getDeclaredField("ignoreCount"); + final Field failuresField = Result.class.getDeclaredField("failures"); countField.setAccessible(true); ignoreCountField.setAccessible(true); @@ -161,10 +161,10 @@ private Result createResult(int runCount, int ignoreCount, Map failures = new CopyOnWriteArrayList<>(); - for (String testMethodName : failureCauses.keySet()) + final CopyOnWriteArrayList failures = new CopyOnWriteArrayList<>(); + for (final String testMethodName : failureCauses.keySet()) { - Failure failure = new Failure(Description.createTestDescription(getClass(), testMethodName), failureCauses.get(testMethodName)); + final Failure failure = new Failure(Description.createTestDescription(getClass(), testMethodName), failureCauses.get(testMethodName)); failures.add(failure); } failuresField.set(result, failures); From 2e5f7201aacad6f4e1f64688533292e4cf473f56 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 28 Aug 2020 15:33:10 +0200 Subject: [PATCH 09/18] build a map using java 9 --- .../xceptance/neodymium/tests/NeodymiumTestSelfTest.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java index d7c1f8e3c..2b3adde16 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java @@ -22,14 +22,7 @@ public class NeodymiumTestSelfTest extends NeodymiumTest public void testCheckFailedOneFromOne() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - final Result result = createResult(1, 0, new HashMap() - { - private static final long serialVersionUID = 1L; - - { - this.put(name.getMethodName() + "1", new RuntimeException(errorMessage)); - } - }); + final Result result = createResult(1, 0, Map.of(name.getMethodName().concat("1"), new RuntimeException(errorMessage))); checkFail(result, 1, 0, 1, errorMessage); } From 61e36acd164cdeb4045d26789b26929641555567 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 28 Aug 2020 15:35:54 +0200 Subject: [PATCH 10/18] RuntimeException replaced with Assert.fail --- src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 2db7952a7..d3052b5dc 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -73,7 +73,7 @@ public void check(Result result, boolean expectedSuccessful, int expectedRunCoun } catch (AssertionError e) { - throw new RuntimeException("Assertion failed. " + e.getMessage() + " Stack trace: " + stackTrace, e); + Assert.fail("Assertion failed. " + e.getMessage() + " Stack trace: " + stackTrace); } } From 56648134b0a72c5651f966cc73cafcdd68d8c2d5 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 28 Aug 2020 15:37:46 +0200 Subject: [PATCH 11/18] check for expectedFailureMessages is not null extracted into if clause --- .../com/xceptance/neodymium/tests/NeodymiumTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index d3052b5dc..f05591e86 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -65,10 +65,13 @@ public void check(Result result, boolean expectedSuccessful, int expectedRunCoun Assert.assertEquals("Method run count", expectedRunCount, result.getRunCount()); Assert.assertEquals("Method ignore count", expectedIgnoreCount, result.getIgnoreCount()); Assert.assertEquals("Method fail count", expectedFailCount, result.getFailureCount()); - for (int i = 0; expectedFailureMessages != null && i < result.getFailures().size(); i++) + if (expectedFailureMessages != null) { - String methodName = result.getFailures().get(i).getDescription().getMethodName(); - Assert.assertEquals("Failure message", expectedFailureMessages.get(methodName), result.getFailures().get(i).getMessage()); + for (int i = 0; i < result.getFailures().size(); i++) + { + String methodName = result.getFailures().get(i).getDescription().getMethodName(); + Assert.assertEquals("Failure message", expectedFailureMessages.get(methodName), result.getFailures().get(i).getMessage()); + } } } catch (AssertionError e) From 3178ba469b2c48f307d5255f3bf380c0c531e9eb Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 28 Aug 2020 15:41:45 +0200 Subject: [PATCH 12/18] all variables in NeodymiumTest made to final --- .../neodymium/tests/NeodymiumTest.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index f05591e86..d41e2615e 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -38,7 +38,7 @@ public static void cleanUp() /** * delete a temporary test file */ - public static void deleteTempFile(File tempFile) + public static void deleteTempFile(final File tempFile) { if (tempFile.exists()) { @@ -54,8 +54,9 @@ public static void deleteTempFile(File tempFile) } } - public void check(Result result, boolean expectedSuccessful, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, - Map expectedFailureMessages) + public void check(final Result result, final boolean expectedSuccessful, final int expectedRunCount, final int expectedIgnoreCount, + final int expectedFailCount, + final Map expectedFailureMessages) { final Optional accumulatedTrace = result.getFailures().stream().map(Failure::getTrace).reduce(String::concat); final String stackTrace = accumulatedTrace.orElse("n/a"); @@ -65,14 +66,17 @@ public void check(Result result, boolean expectedSuccessful, int expectedRunCoun Assert.assertEquals("Method run count", expectedRunCount, result.getRunCount()); Assert.assertEquals("Method ignore count", expectedIgnoreCount, result.getIgnoreCount()); Assert.assertEquals("Method fail count", expectedFailCount, result.getFailureCount()); + if (expectedFailureMessages != null) { - for (int i = 0; i < result.getFailures().size(); i++) + final int failureCount = result.getFailureCount(); + for (int i = 0; i < failureCount; i++) { - String methodName = result.getFailures().get(i).getDescription().getMethodName(); + final String methodName = result.getFailures().get(i).getDescription().getMethodName(); Assert.assertEquals("Failure message", expectedFailureMessages.get(methodName), result.getFailures().get(i).getMessage()); } } + } catch (AssertionError e) { @@ -90,7 +94,7 @@ public void check(Result result, boolean expectedSuccessful, int expectedRunCoun * @param expectedIgnoreCount * expected number of ignored tests */ - public void checkPass(Result result, int expectedRunCount, int expectedIgnoreCount) + public void checkPass(final Result result, final int expectedRunCount, final int expectedIgnoreCount) { check(result, true, expectedRunCount, expectedIgnoreCount, 0, null); } @@ -107,7 +111,7 @@ public void checkPass(Result result, int expectedRunCount, int expectedIgnoreCou * @param expectedFailCount * expected number of failed tests */ - public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount) + public void checkFail(final Result result, final int expectedRunCount, final int expectedIgnoreCount, final int expectedFailCount) { check(result, false, expectedRunCount, expectedIgnoreCount, expectedFailCount, null); } @@ -126,10 +130,10 @@ public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCou * @param expectedFailureMessage * expected failure message for all failures */ - public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, - String expectedFailureMessage) + public void checkFail(final Result result, final int expectedRunCount, final int expectedIgnoreCount, final int expectedFailCount, + final String expectedFailureMessage) { - HashMap expectedFailureMessages = new HashMap(); + final HashMap expectedFailureMessages = new HashMap(); for (Failure failure : result.getFailures()) { expectedFailureMessages.put(failure.getDescription().getMethodName(), expectedFailureMessage); @@ -151,16 +155,16 @@ public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCou * @param expectedFailureMessages * Map with test method name as key and corresponding expected failure message as value */ - public void checkFail(Result result, int expectedRunCount, int expectedIgnoreCount, int expectedFailCount, - Map expectedFailureMessages) + public void checkFail(final Result result, final int expectedRunCount, final int expectedIgnoreCount, final int expectedFailCount, + final Map expectedFailureMessages) { check(result, false, expectedRunCount, expectedIgnoreCount, expectedFailCount, expectedFailureMessages); } - public void checkDescription(Description testDescription, String[] expectedTestDescription) + public void checkDescription(final Description testDescription, final String[] expectedTestDescription) { - ArrayList testChildren = testDescription.getChildren(); - String[] actualDescription = new String[testChildren.size()]; + final ArrayList testChildren = testDescription.getChildren(); + final String[] actualDescription = new String[testChildren.size()]; for (int i = 0; i < testChildren.size(); i++) { @@ -172,7 +176,7 @@ public void checkDescription(Description testDescription, String[] expectedTestD Assert.assertArrayEquals(expectedTestDescription, actualDescription); } - public void checkDescription(Class clazz, String[] expectedTestDescription) throws Throwable + public void checkDescription(final Class clazz, final String[] expectedTestDescription) throws Throwable { checkDescription(new NeodymiumRunner(clazz).getDescription(), expectedTestDescription); } @@ -183,15 +187,15 @@ public void checkDescription(Class clazz, String[] expectedTestDescription) t * @param map * @param file */ - public static void writeMapToPropertiesFile(Map map, File file) + public static void writeMapToPropertiesFile(final Map map, final File file) { try { - String propertiesString = map.keySet().stream() - .map(key -> key + "=" + map.get(key)) - .collect(Collectors.joining("\r\n")); + final String propertiesString = map.keySet().stream() + .map(key -> key + "=" + map.get(key)) + .collect(Collectors.joining("\r\n")); - FileOutputStream outputStream = new FileOutputStream(file); + final FileOutputStream outputStream = new FileOutputStream(file); outputStream.write(propertiesString.getBytes()); outputStream.close(); } @@ -200,4 +204,4 @@ public static void writeMapToPropertiesFile(Map map, File file) throw new RuntimeException(e); } } -} +} \ No newline at end of file From cec86390f5a3893525183e2a2b69cf00ce4c1492 Mon Sep 17 00:00:00 2001 From: Olha Omelianchuk Date: Fri, 28 Aug 2020 15:42:17 +0200 Subject: [PATCH 13/18] javadoc improved --- .../neodymium/tests/NeodymiumTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index d41e2615e..ed5552b3b 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -85,10 +85,10 @@ public void check(final Result result, final boolean expectedSuccessful, final i } /** - * Assert all tests in run were successful + * Assert that all tests have passed. * * @param result - * test result to make assertions on + * test result to validate * @param expectedRunCount * expected number of run tests (including ignored) * @param expectedIgnoreCount @@ -100,10 +100,10 @@ public void checkPass(final Result result, final int expectedRunCount, final int } /** - * Assert the are one or more failed tests in run + * Assert that at least one test has failed. * * @param result - * test result to make assertions on + * test result to validate * @param expectedRunCount * expected number of run tests (including ignored) * @param expectedIgnoreCount @@ -117,10 +117,10 @@ public void checkFail(final Result result, final int expectedRunCount, final int } /** - * Assert the are one or more failed tests in run + * Assert that at least one test has failed. * * @param result - * test result to make assertions on + * test result to validate * @param expectedRunCount * expected number of run tests (including ignored) * @param expectedIgnoreCount @@ -128,7 +128,7 @@ public void checkFail(final Result result, final int expectedRunCount, final int * @param expectedFailCount * expected number of failed tests * @param expectedFailureMessage - * expected failure message for all failures + * expected message of all failures (same message for each failure) */ public void checkFail(final Result result, final int expectedRunCount, final int expectedIgnoreCount, final int expectedFailCount, final String expectedFailureMessage) @@ -142,10 +142,10 @@ public void checkFail(final Result result, final int expectedRunCount, final int } /** - * Assert the are one or more failed tests in run + * Assert that at least one test has failed. * * @param result - * test result to make assertions on + * test result to validate * @param expectedRunCount * expected number of run tests (including ignored) * @param expectedIgnoreCount @@ -153,7 +153,7 @@ public void checkFail(final Result result, final int expectedRunCount, final int * @param expectedFailCount * expected number of failed tests * @param expectedFailureMessages - * Map with test method name as key and corresponding expected failure message as value + * expected failures messages mapped by name of test method */ public void checkFail(final Result result, final int expectedRunCount, final int expectedIgnoreCount, final int expectedFailCount, final Map expectedFailureMessages) From 2ac1cd1fd4fe4bfc51eed278605aab9a48387a6b Mon Sep 17 00:00:00 2001 From: Marcel Pfotenhauer Date: Mon, 31 Aug 2020 15:28:00 +0200 Subject: [PATCH 14/18] #121: simplified code by usin Map.of() --- .../xceptance/neodymium/util/Neodymium.java | 1 - .../neodymium/util/SelenideAddons.java | 1 - .../tests/NeodymiumTestSelfTest.java | 68 +++++-------------- 3 files changed, 16 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/xceptance/neodymium/util/Neodymium.java b/src/main/java/com/xceptance/neodymium/util/Neodymium.java index 1f841ae1a..dde01bc3f 100644 --- a/src/main/java/com/xceptance/neodymium/util/Neodymium.java +++ b/src/main/java/com/xceptance/neodymium/util/Neodymium.java @@ -396,5 +396,4 @@ public static boolean isSite(String... sites) } return false; } - } diff --git a/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java b/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java index a5bf0e382..bf5793649 100644 --- a/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java +++ b/src/main/java/com/xceptance/neodymium/util/SelenideAddons.java @@ -403,7 +403,6 @@ public static void wrapAssertionError(final Runnable runnable) * @param verticalMovement * The offset for the vertical movement */ - public static void dragAndDrop(SelenideElement elementToMove, int horizontalMovement, int verticalMovement) { // perform drag and drop via the standard Selenium way diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java index 2b3adde16..a518c276d 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTestSelfTest.java @@ -1,7 +1,6 @@ package com.xceptance.neodymium.tests; import java.lang.reflect.Field; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicInteger; @@ -30,29 +29,18 @@ public void testCheckFailedOneFromOne() throws NoSuchFieldException, SecurityExc public void testCheckFailedOneFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - final Result result = createResult(2, 0, new HashMap() - { - private static final long serialVersionUID = 2L; + final Result result = createResult(2, 0, Map.of(name.getMethodName().concat("1"), new RuntimeException(errorMessage))); - { - this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); - } - }); checkFail(result, 2, 0, 1, errorMessage); } @Test public void testCheckFailedTwoFromTwoNumber() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Result result = createResult(2, 0, new HashMap() - { - private static final long serialVersionUID = 3L; - - { - this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); - this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 1")); - } - }); + final String errorMessage1 = "This is RuntimeException 1"; + final String errorMessage2 = "This is RuntimeException 2"; + final Result result = createResult(2, 0, Map.of(name.getMethodName().concat("1"), new RuntimeException(errorMessage1), + name.getMethodName().concat("2"), new RuntimeException(errorMessage2))); // no assertion for failure message, as one is only possible for single fail checkFail(result, 2, 0, 2); @@ -61,41 +49,24 @@ public void testCheckFailedTwoFromTwoNumber() throws NoSuchFieldException, Secur @Test public void testCheckFailedTwoFromTwoOneFailureMessage() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Result result = createResult(2, 0, new HashMap() - { - private static final long serialVersionUID = 4L; - - { - this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); - this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 1")); - } - }); + final String errorMessage = "This is RuntimeException 1"; + final Result result = createResult(2, 0, Map.of(name.getMethodName().concat("1"), new RuntimeException(errorMessage), + name.getMethodName().concat("2"), new RuntimeException(errorMessage))); // no assertion for failure message, as one is only possible for single fail - checkFail(result, 2, 0, 2, "This is RuntimeException 1"); + checkFail(result, 2, 0, 2, errorMessage); } @Test public void testCheckFailedTwoFromTwoTwoFailureMessages() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - final Result result = createResult(2, 0, new HashMap() - { - private static final long serialVersionUID = 5L; - - { - this.put(name.getMethodName() + "1", new RuntimeException("This is RuntimeException 1")); - this.put(name.getMethodName() + "2", new RuntimeException("This is RuntimeException 2")); - } - }); - final HashMap expectedFailureMessages = new HashMap() - { - private static final long serialVersionUID = 6L; + final String errorMessage1 = "This is RuntimeException 1"; + final String errorMessage2 = "This is RuntimeException 2"; + final Result result = createResult(2, 0, Map.of(name.getMethodName().concat("1"), new RuntimeException(errorMessage1), + name.getMethodName().concat("2"), new RuntimeException(errorMessage2))); + final Map expectedFailureMessages = Map.of(name.getMethodName().concat("1"), errorMessage1, + name.getMethodName().concat("2"), errorMessage2); - { - this.put(name.getMethodName() + "1", "This is RuntimeException 1"); - this.put(name.getMethodName() + "2", "This is RuntimeException 2"); - } - }; // no assertion for failure message, as one is only possible for single fail checkFail(result, 2, 0, 2, expectedFailureMessages); } @@ -104,14 +75,7 @@ public void testCheckFailedTwoFromTwoTwoFailureMessages() throws NoSuchFieldExce public void testCheckOneFailedOneIgnoredFromTwo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { final String errorMessage = "This is RuntimeException 1"; - final Result result = createResult(2, 1, new HashMap() - { - private static final long serialVersionUID = 7L; - - { - this.put(name.getMethodName() + "1", new RuntimeException(errorMessage)); - } - }); + final Result result = createResult(2, 1, Map.of(name.getMethodName().concat("1"), new RuntimeException(errorMessage))); checkFail(result, 2, 1, 1, errorMessage); } From 7d95390ce8683ab141f53021a685a32301e88536 Mon Sep 17 00:00:00 2001 From: Marcel Pfotenhauer Date: Mon, 31 Aug 2020 15:31:36 +0200 Subject: [PATCH 15/18] #121: added a newline --- src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index ed5552b3b..5fdb15532 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -54,6 +54,7 @@ public static void deleteTempFile(final File tempFile) } } + // TODO JavaDoc public void check(final Result result, final boolean expectedSuccessful, final int expectedRunCount, final int expectedIgnoreCount, final int expectedFailCount, final Map expectedFailureMessages) @@ -204,4 +205,4 @@ public static void writeMapToPropertiesFile(final Map map, final throw new RuntimeException(e); } } -} \ No newline at end of file +} From a4e192d4063832d63178b0e6239f8b95d395ae2a Mon Sep 17 00:00:00 2001 From: Marcel Pfotenhauer Date: Mon, 31 Aug 2020 21:07:29 +0200 Subject: [PATCH 16/18] #121: added java doc --- .../neodymium/tests/NeodymiumTest.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 311617da9..003f5697b 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -39,6 +39,9 @@ public static void cleanUp() /** * delete a temporary test file + * + * @param tempFile + * the tempFile that should be deleted after test execution */ public static void deleteTempFile(final File tempFile) { @@ -56,15 +59,30 @@ public static void deleteTempFile(final File tempFile) } } - public void check(final Result result, final boolean expectedSuccessful, final int expectedRunCount, final int expectedIgnoreCount, - final int expectedFailCount, - final Map expectedFailureMessages) + /** + * Basic method to perform assertions on a given test result. + * + * @param result + * test result to validate + * @param expectSuccessful + * the test result should be successful + * @param expectedRunCount + * expected number of run tests (including ignored) + * @param expectedIgnoreCount + * expected number of ignored tests + * @param expectedFailCount + * expected number of failed tests + * @param expectedFailureMessages + * expected message of all failures (same message for each failure) + */ + public void check(final Result result, final boolean expectSuccessful, final int expectedRunCount, final int expectedIgnoreCount, + final int expectedFailCount, final Map expectedFailureMessages) { final Optional accumulatedTrace = result.getFailures().stream().map(Failure::getTrace).reduce(String::concat); final String stackTrace = accumulatedTrace.orElse("n/a"); try { - Assert.assertEquals("Test successful", expectedSuccessful, result.wasSuccessful()); + Assert.assertEquals("Test successful", expectSuccessful, result.wasSuccessful()); Assert.assertEquals("Method run count", expectedRunCount, result.getRunCount()); Assert.assertEquals("Method ignore count", expectedIgnoreCount, result.getIgnoreCount()); Assert.assertEquals("Method fail count", expectedFailCount, result.getFailureCount()); @@ -78,7 +96,6 @@ public void check(final Result result, final boolean expectedSuccessful, final i Assert.assertEquals("Failure message", expectedFailureMessages.get(methodName), result.getFailures().get(i).getMessage()); } } - } catch (AssertionError e) { From 98dcbf8b0b59818ac020e51518eabb3acf0333ed Mon Sep 17 00:00:00 2001 From: Marcel Pfotenhauer Date: Tue, 1 Sep 2020 10:35:22 +0200 Subject: [PATCH 17/18] #121: added java doc --- .../xceptance/neodymium/tests/NeodymiumTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 003f5697b..7335368be 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -180,6 +180,14 @@ public void checkFail(final Result result, final int expectedRunCount, final int check(result, false, expectedRunCount, expectedIgnoreCount, expectedFailCount, expectedFailureMessages); } + /** + * Assert that the test description is valid. + * + * @param testDescription + * the test description that should be tested + * @param expectedTestDescription + * expected test description as String array + */ public void checkDescription(final Description testDescription, final String[] expectedTestDescription) { final ArrayList testChildren = testDescription.getChildren(); @@ -195,6 +203,14 @@ public void checkDescription(final Description testDescription, final String[] e Assert.assertArrayEquals(expectedTestDescription, actualDescription); } + /** + * Assert that the test description is valid. + * + * @param clazz + * the class whose description should be tested + * @param expectedTestDescription + * expected test description as String array + */ public void checkDescription(final Class clazz, final String[] expectedTestDescription) throws Throwable { checkDescription(new NeodymiumRunner(clazz).getDescription(), expectedTestDescription); From 862d3ec00d812c233286402011f368517661970b Mon Sep 17 00:00:00 2001 From: Marcel Pfotenhauer Date: Tue, 1 Sep 2020 10:58:33 +0200 Subject: [PATCH 18/18] #121: improved java doc --- src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java index 7335368be..5d2c6c348 100644 --- a/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java +++ b/src/test/java/com/xceptance/neodymium/tests/NeodymiumTest.java @@ -73,7 +73,7 @@ public static void deleteTempFile(final File tempFile) * @param expectedFailCount * expected number of failed tests * @param expectedFailureMessages - * expected message of all failures (same message for each failure) + * expected failure messages mapped by name of test method */ public void check(final Result result, final boolean expectSuccessful, final int expectedRunCount, final int expectedIgnoreCount, final int expectedFailCount, final Map expectedFailureMessages)