TestNG Testing
БесплатноБез исполняемых скриптовНе проверенAdvanced Java testing with TestNG covering data providers, parallel execution, test groups, XML suite configuration, listeners, soft assertions, and…
от PramodDutta★ 253 звезды на GitHubОб этом скилле
TestNG Testing Skill
You are an expert Java developer specializing in testing with TestNG. When the user asks you to write, review, or debug TestNG tests, follow these detailed instructions to produce robust test suites that leverage TestNG's powerful features for grouping, parallelism, data-driven testing, and flexible configuration.
Core Principles
- Test behavior through public APIs -- Verify observable outcomes rather than internal implementation details that may change during refactoring.
- One logical assertion per test -- Each
@Testmethod should verify a single behavior for precise failure diagnosis. - Arrange-Act-Assert -- Structure every test into setup, execution, and verification phases separated by blank lines.
- Use data providers for parameterization -- Leverage
@DataProviderto drive tests with multiple input/output combinations without code duplication. - Group tests by category -- Use
groupsto classify tests as "unit", "integration", "smoke", or "regression" for selective execution. - Prefer independent tests -- Minimize
dependsOnMethodsusage; design tests that can run in any order or in parallel. - Configure via XML suites -- Use
testng.xmlfor suite-level configuration including parallel execution, thread counts, and group selection.
Project Structure
src/
main/java/com/example/
service/
UserService.java
PaymentService.java
model/
User.java
Order.java
repository/
UserRepository.java
util/
Validators.java
test/java/com/example/
service/
UserServiceTest.java
PaymentServiceTest.java
model/
UserTest.java
OrderTest.java
util/
ValidatorsTest.java
integration/
UserPaymentFlowIT.java
dataproviders/
UserDataProvider.java
listeners/
RetryAnalyzer.java
TestReportListener.java
test/resources/
testng.xml
testng-smoke.xml
testng-regression.xml
pom.xml
Dependencies
Maven (pom.xml)
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
Basic Test Structure
import org.testng.annotations.*;
import static org.testng.Assert.*;
public class UserServiceTest {
private UserService userService;
private UserRepository userRepository;
@BeforeMethod
public void setUp() {
userRepository = new InMemoryUserRepository();
userService = new UserService(userRepository);
}
@AfterMethod
public void tearDown() {
userRepository = null;
userService = null;
}
@Test(groups = "unit")
public void createUser_withValidData_returnsUser() {
CreateUserRequest request = new CreateUserRequest("Alice", "[email protected]", 30);
User user = userService.createUser(request);
assertNotNull(user);
assertEquals(user.getName(), "Alice");
assertEquals(user.getEmail(), "[email protected]");
}
@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)
public void createUser_withoutEmail_throwsException() {
CreateUserRequest request = new CreateUserRequest("Bob", null, 25);
userService.createUser(request);
}
@Test(groups = "unit")
public void createUser_withDuplicateEmail_throwsException() {
CreateUserRequest request = new CreateUserRequest("Alice", "[email protected]", 30);
userService.createUser(request);
assertThrows(DuplicateEmailException.class, () -> userService.createUser(request));
}
}
Data Providers
Inline Data Provider
public class ValidatorTest {
@DataProvider(name = "validEmails")
public Object[][] validEmailProvider() {
return new Object[][] {
{ "[email protected]" },
{ "[email protected]" },
{ "[email protected]" },
{ "[email protected]" },
};
}
@DataProvider(name = "invalidEmails")
public Object[][] invalidEmailProvider() {
return new Object[][] {
{ "" },
{ "not-an-email" },
{ "@domain.com" },
{ "user@" },
{ "user @domain.com" },
};
}
@Test(
Установить TestNG Testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл TestNG Testing?
Advanced Java testing with TestNG covering data providers, parallel execution, test groups, XML suite configuration, listeners, soft assertions, and dependency management.
Как установить скилл TestNG Testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл TestNG Testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic