mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-16 01:12:13 +08:00
* feat: update tinystruct-patterns skill with comprehensive expert knowledge * Update skills/tinystruct-patterns/SKILL.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update skills/tinystruct-patterns/SKILL.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update skills/tinystruct-patterns/references/database.md Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update testing.md * Update database.md --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1.9 KiB
1.9 KiB
tinystruct Testing Patterns
When to Use
Use these patterns when writing unit tests for your applications with JUnit 5. Essential for verifying action logic, routing registration, and HTTP mode behavior.
How It Works
Unit Testing Applications
ActionRegistry is a singleton. To test an application:
- Instantiate the application.
- Provide a
Settingsobject (triggersinit()and annotation processing). - Use
app.invoke(path, args)to test logic directly.
HTTP Integration Testing
For tests involving the built-in HTTP server:
- Start
HttpServerin a background thread. - Use
ApplicationManager.call("start", context, Action.Mode.CLI)to boot. - Wait for the port to be open using a
Socket. - Use
URLRequestandHTTPHandlerto perform actual requests.
Examples
Unit Test
import org.junit.jupiter.api.*;
import org.tinystruct.system.Settings;
class MyAppTest {
private MyApp app;
@BeforeEach
void setUp() {
app = new MyApp();
app.setConfiguration(new Settings());
app.init(); // triggers @Action annotation processing and registers all actions
}
@Test
void testHello() throws Exception {
Object result = app.invoke("hello");
Assertions.assertEquals("Hello!", result);
}
@Test
void testGreet() throws Exception {
Object result = app.invoke("greet", new Object[]{"James"});
Assertions.assertEquals("Hello, James!", result);
}
}
ActionRegistry Match Testing
@Test
void testRouting() {
ActionRegistry registry = ActionRegistry.getInstance();
Action action = registry.getAction("greet/James");
Assertions.assertNotNull(action);
}
HTTP Integration Pattern
Reference: src/test/java/org/tinystruct/system/HttpServerHttpModeTest.java
// Pattern:
// 1. Start server in thread
// 2. Poll for port availability
// 3. Send HTTP request via HTTPHandler
// 4. Assert response body/status