-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create TestDataManagementExample.java
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |