Skip to content

Instantly share code, notes, and snippets.

We can make this file beautiful and searchable if this error is corrected: It looks like row 4 should actually have 1 column, instead of 2. in line 3.
+-----------+-----------------------------------+-----------------------------------+----------------------------+----------------------------+
| Tool | Overview | Key Features | Ideal Use Cases | Limitations |
+-----------+-----------------------------------+-----------------------------------+----------------------------+----------------------------+
| JUnit | Staple in Java testing, known | Basic pass/fail reporting. | Straightforward unit | Lacks advanced reporting |
| | for simplicity and efficiency. | | testing in Java. | and analytics. |
+-----------+-----------------------------------+-----------------------------------+----------------------------+----------------------------+
| TestNG | Advanced version of JUnit, | Wide range of tests, including | Complex Java projects | More complex setup; may |
| | mo
public interface TestObject {
void performTest();
}
public class TestObjectFactory {
public static TestObject createTestObject(String type) {
if (type.equals("TypeA")) {
return new TestObjectA();
} else if (type.equals("TypeB")) {
return new TestObjectB();
public class WebDriverSingleton {
private static WebDriver instance;
private WebDriverSingleton() {
// Private constructor to prevent external instantiation
}
public static WebDriver getInstance() {
if (instance == null) {
// Create a new WebDriver instance
public class LoginPage {
private WebDriver driver;
// Web elements
private By usernameInput = By.id("username");
private By passwordInput = By.id("password");
private By loginButton = By.id("loginButton");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
public class LoginPage {
private WebDriver driver;
// Web elements
private By usernameInput = By.id("username");
private By passwordInput = By.id("password");
private By loginButton = By.id("loginButton");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
// Store contract remotely
publisher := dsl.Publisher{}
err = publisher.Publish(types.PublishRequest{
PactURLs: []string{"../client/pacts/sample_consumer-sample_provider.json"},
PactBroker: "https://pen.pactflow.io/", //link to your remote Contract broker
BrokerToken: "xxx", //your PactFlow token
ConsumerVersion: "1.0.0",
Tags: []string{"1.0.0", "latest"},
})
if err != nil {
type Car struct {
ID string `json:"id"`
Title string `json:"title"`
Color string `json:"color"`
}
var Cars = []Car{
{ID: "1", Title: "BMW", Color: "Black"},
{ID: "2", Title: "Tesla", Color: "Red"},
}
_, err := pact.VerifyProvider(t, types.VerifyRequest{
ProviderBaseURL: "http://127.0.0.1:8080", //provider's URL
BrokerURL: "https://pen.pactflow.io", //link to your remote Contract broker
BrokerToken: "xxx", //your PactFlow token
PublishVerificationResults: true,
ProviderVersion: "1.0.0",
})
if err != nil {
t.Fatal(err)
publisher := dsl.Publisher{}
err := publisher.Publish(types.PublishRequest{
PactURLs: []string{"../client/pacts/sample_consumer-sample_provider.json"},
PactBroker: "https://pen.pactflow.io/", //link to your remote Contract broker
BrokerToken: "xxx", //your PactFlow token
ConsumerVersion: "1.0.0",
Tags: []string{"1.0.0", "latest"},
})
if err != nil {
t.Fatal(err)
func startProvider() {
main()
}
func TestServerPact_Verification(t *testing.T) {
go startProvider()
var dir, _ = os.Getwd()
var pactDir = fmt.Sprintf("%s/../client/pacts", dir)