Skip to content

Commit

Permalink
Create TestDataManagementExample.java
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvolod authored Feb 20, 2024
1 parent a1381e6 commit c8bc90f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions java/TestDataManagementExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import org.junit.*;

public class TestDataManagementExample {
// Problem: Static, Hard-Coded Test Data
@Test
public void testWithStaticData() {
// Use static data, leading to potential test data pollution
String userId = "staticUserId"; // Static user ID
}

// Solution: Dynamic Test Data via API
private String dynamicUserId;

@Before
public void setUp() {
// Dynamically create test data
dynamicUserId = APIClient.create("/users", "dynamicUser");
}

@Test
public void testWithDynamicData() {
// Use dynamically created user ID
System.out.println("Testing with user: " + dynamicUserId);
// Test logic here
}

@After
public void tearDown() {
// Clean up dynamic test data
APIClient.delete("/users/" + dynamicUserId);
}
}

0 comments on commit c8bc90f

Please sign in to comment.