Loading...
Loading...
Testing frameworks for web, mobile, API, and unit testing
npx skill4agent add davincidreams/agent-team-plugins test-frameworks// Java Selenium example
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
WebElement element = driver.findElement(By.id("username"));
element.sendKeys("testuser");
driver.quit();// Cypress example
describe('Login', () => {
it('should login successfully', () => {
cy.visit('/login');
cy.get('#username').type('testuser');
cy.get('#password').type('password');
cy.get('#login').click();
cy.url().should('include', '/dashboard');
});
});// Playwright JavaScript example
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.fill('#username', 'testuser');
await page.click('#login');
await browser.close();
})();// Puppeteer example
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page.type('#username', 'testuser');
await page.click('#login');
await browser.close();
})();// Jest example
describe('Calculator', () => {
test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});
test('async operation', async () => {
const result = await fetchData();
expect(result).toEqual({ data: 'test' });
});
});// Mocha example with Chai
const { expect } = require('chai');
const sinon = require('sinon');
describe('UserService', () => {
it('should return user data', async () => {
const user = await userService.getUser(1);
expect(user).to.have.property('id', 1);
});
});// Vitest example
import { describe, it, expect } from 'vitest';
describe('Math', () => {
it('should add numbers', () => {
expect(add(1, 2)).toBe(3);
});
});// Jasmine example
describe('Calculator', () => {
it('should add numbers', () => {
const result = add(1, 2);
expect(result).toBe(3);
});
});# pytest example
def test_addition():
assert add(1, 2) == 3
@pytest.fixture
def user_data():
return {'id': 1, 'name': 'Test User'}
def test_user(user_data):
assert user_data['name'] == 'Test User'# unittest example
import unittest
class TestCalculator(unittest.TestCase):
def test_addition(self):
result = add(1, 2)
self.assertEqual(result, 3)// JUnit 5 example
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class CalculatorTest {
@Test
void testAddition() {
assertEquals(3, add(1, 2));
}
}// TestNG example
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class CalculatorTest {
@Test
public void testAddition() {
assertEquals(add(1, 2), 3);
}
}// Mockito example
import static org.mockito.Mockito.*;
List<String> mockList = mock(List.class);
when(mockList.get(0)).thenReturn("first");
assertEquals("first", mockList.get(0));
verify(mockList).get(0);// Appium Java example
AppiumDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.findElement(By.id("username")).sendKeys("testuser");
driver.quit();// Espresso example
onView(withId(R.id.username))
.perform(typeText("testuser"))
.check(matches(withText("testuser")));// XCUITest example
let app = XCUIApplication()
app.textFields["username"].tap()
app.textFields["username"].typeText("testuser")// Postman test script
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response has data", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.data).to.exist;
});// REST Assured example
given()
.header("Content-Type", "application/json")
.body("{\"name\":\"test\"}")
.when()
.post("/api/users")
.then()
.statusCode(201)
.body("name", equalTo("test"));// Supertest example
const request = require('supertest');
const app = require('./app');
describe('API', () => {
it('should create user', async () => {
const res = await request(app)
.post('/api/users')
.send({ name: 'test' })
.expect(201);
expect(res.body.name).toBe('test');
});
});