Skip to content

Commit

Permalink
Merge pull request #268 from Xceptance/#266-bug-test-context-is-not-c…
Browse files Browse the repository at this point in the history
…leared-after-run

[#266] clear test context after run
  • Loading branch information
wurzelkuchen authored Jul 10, 2024
2 parents 51be3e9 + 7d48d09 commit a6eed11
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.xceptance.neodymium.junit5.filtering.FilterTestMethodCallback;
import com.xceptance.neodymium.junit5.filtering.WipTestMethodCallback;
import com.xceptance.neodymium.junit5.testdata.TestdataCallback;
import com.xceptance.neodymium.util.Neodymium;

public class TemplateInvocationContext implements TestTemplateInvocationContext
{
Expand Down Expand Up @@ -40,6 +41,7 @@ public String getDisplayName(int invocationIndex)
@Override
public List<Extension> getAdditionalExtensions()
{
Neodymium.clearThreadContext();
List<Extension> extentions = new LinkedList<>();
if (browser != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.xceptance.neodymium.junit4.testclasses.data;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.xceptance.neodymium.junit4.NeodymiumRunner;
import com.xceptance.neodymium.util.DataUtils;

@RunWith(NeodymiumRunner.class)
public class ClearedContextBetweenMethods
{
@Test
public void test()
{
if (DataUtils.asString("testId").equals("fist set"))
{
Assert.assertEquals("Test data is not matching the test expectations", "val1", DataUtils.asString("key1"));
Assert.assertEquals("Test data is not matching the test expectations", "val2", DataUtils.asString("key2"));
}
else
{
Assert.assertEquals("Test data is not overwritten", "new val", DataUtils.asString("key1"));
Assert.assertNull("Test data context is not cleared", DataUtils.asString("key2", null));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.xceptance.neodymium.junit5.testclasses.data;

import org.junit.Assert;

import com.xceptance.neodymium.junit5.NeodymiumTest;
import com.xceptance.neodymium.util.DataUtils;

public class CleanedContextBetweenMethods
{
@NeodymiumTest
public void test()
{
if (DataUtils.asString("testId").equals("fist set"))
{
Assert.assertEquals("Test data is not matching the test expectations", "val1", DataUtils.asString("key1"));
Assert.assertEquals("Test data is not matching the test expectations", "val2", DataUtils.asString("key2"));
}
else
{
Assert.assertEquals("Test data is not overwritten", "new val", DataUtils.asString("key1"));
Assert.assertNull("Test data context is not cleared", DataUtils.asString("key2", null));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"testId": "fist set",
"key1": "val1",
"key2": "val2"
},
{
"testId": "second set",
"key1": "new val"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"testId": "fist set",
"key1": "val1",
"key2": "val2"
},
{
"testId": "second set",
"key1": "new val"
}
]

0 comments on commit a6eed11

Please sign in to comment.