Generate test assertions from existing code implementation. Use when the user has implementation code without tests or incomplete test coverage, and needs assertions synthesized by analyzing the code's behavior, inputs, outputs, and state changes. Supports Python (pytest/unittest), Java (JUnit/AssertJ), and JavaScript/TypeScript (Jest/Chai). Handles equality checks, collections, exceptions, and state verification.
Install with Tessl CLI
npx tessl i github:ArabelaTso/Skills-4-SE --skill assertion-synthesizer86
Does it follow best practices?
If you maintain this skill, you can automatically optimize it using the tessl CLI to improve its score:
npx tessl skill review --optimize ./path/to/skillValidation for skill structure
Generate comprehensive test assertions by analyzing code implementation, behavior, and expected outputs.
Read and understand the implementation to identify testable behavior:
Extract scenarios that need assertions:
Create appropriate assertions for each scenario:
Assertion Types:
assert result == expected, assertEquals(expected, actual)assert is_valid, assertTrue(condition)assert item in list, assertContains(list, item)pytest.raises(Exception), assertThrows(Exception)assert obj.status == "active", assertEquals("active", obj.getStatus())Organize assertions into well-structured test functions:
Ensure all important behaviors have assertions:
def test_basic_equality():
# Arrange
calculator = Calculator()
# Act
result = calculator.add(2, 3)
# Assert
assert result == 5
def test_collection_membership():
items = get_active_items()
assert "item1" in items
assert len(items) == 3
def test_exception_handling():
with pytest.raises(ValueError, match="Invalid input"):
process_data(None)
def test_state_change():
user = User("Alice")
user.activate()
assert user.is_active == True
assert user.status == "active"def test_basic_equality(self):
calculator = Calculator()
result = calculator.add(2, 3)
self.assertEqual(result, 5)
def test_collection_membership(self):
items = get_active_items()
self.assertIn("item1", items)
self.assertEqual(len(items), 3)
def test_exception_handling(self):
with self.assertRaises(ValueError):
process_data(None)
def test_state_change(self):
user = User("Alice")
user.activate()
self.assertTrue(user.is_active)
self.assertEqual(user.status, "active")@Test
void testBasicEquality() {
Calculator calculator = new Calculator();
int result = calculator.add(2, 3);
assertThat(result).isEqualTo(5);
}
@Test
void testCollectionMembership() {
List<String> items = getActiveItems();
assertThat(items).contains("item1");
assertThat(items).hasSize(3);
}
@Test
void testExceptionHandling() {
assertThatThrownBy(() -> processData(null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid input");
}
@Test
void testStateChange() {
User user = new User("Alice");
user.activate();
assertThat(user.isActive()).isTrue();
assertThat(user.getStatus()).isEqualTo("active");
}test('basic equality', () => {
const calculator = new Calculator();
const result = calculator.add(2, 3);
expect(result).toBe(5);
});
test('collection membership', () => {
const items = getActiveItems();
expect(items).toContain('item1');
expect(items).toHaveLength(3);
});
test('exception handling', () => {
expect(() => processData(null))
.toThrow('Invalid input');
});
test('state change', () => {
const user = new User('Alice');
user.activate();
expect(user.isActive).toBe(true);
expect(user.status).toBe('active');
});Analyze what the function returns and assert on it:
# Code:
def get_full_name(first, last):
return f"{first} {last}"
# Synthesized assertion:
def test_get_full_name():
result = get_full_name("John", "Doe")
assert result == "John Doe"
assert isinstance(result, str)Identify state changes and mutations:
# Code:
def withdraw(account, amount):
if account.balance >= amount:
account.balance -= amount
return True
return False
# Synthesized assertions:
def test_withdraw_success():
account = Account(balance=100)
result = withdraw(account, 50)
assert result == True
assert account.balance == 50
def test_withdraw_insufficient_funds():
account = Account(balance=30)
result = withdraw(account, 50)
assert result == False
assert account.balance == 30 # Balance unchangedTest each branch:
# Code:
def classify_age(age):
if age < 0:
raise ValueError("Invalid age")
elif age < 18:
return "minor"
elif age < 65:
return "adult"
else:
return "senior"
# Synthesized assertions:
def test_classify_age_invalid():
with pytest.raises(ValueError):
classify_age(-1)
def test_classify_age_minor():
assert classify_age(10) == "minor"
assert classify_age(17) == "minor"
def test_classify_age_adult():
assert classify_age(18) == "adult"
assert classify_age(64) == "adult"
def test_classify_age_senior():
assert classify_age(65) == "senior"
assert classify_age(100) == "senior"Assert on collection properties:
# Code:
def filter_active_users(users):
return [u for u in users if u.is_active]
# Synthesized assertions:
def test_filter_active_users():
users = [
User("Alice", is_active=True),
User("Bob", is_active=False),
User("Charlie", is_active=True)
]
result = filter_active_users(users)
assert len(result) == 2
assert all(u.is_active for u in result)
assert result[0].name == "Alice"
assert result[1].name == "Charlie"Verify object properties:
# Code:
class ShoppingCart:
def __init__(self):
self.items = []
self.total = 0
def add_item(self, item, price):
self.items.append(item)
self.total += price
# Synthesized assertions:
def test_shopping_cart_add_item():
cart = ShoppingCart()
# Initial state
assert cart.items == []
assert cart.total == 0
# After first item
cart.add_item("book", 20)
assert len(cart.items) == 1
assert "book" in cart.items
assert cart.total == 20
# After second item
cart.add_item("pen", 5)
assert len(cart.items) == 2
assert cart.total == 25assert result == 5 over assert result > 0test_withdraw_insufficient_funds not test_case_2Multiple assertions for comprehensive verification:
def test_user_registration():
user = register_user("alice@example.com", "password123")
# Verify all important properties
assert user.email == "alice@example.com"
assert user.is_active == False # Not activated yet
assert user.created_at is not None
assert user.id is not None
assert len(user.roles) == 1
assert "user" in user.rolesParametrized tests for multiple inputs:
@pytest.mark.parametrize("input,expected", [
(0, "zero"),
(1, "one"),
(5, "many"),
(100, "many"),
])
def test_number_to_word(input, expected):
assert number_to_word(input) == expectedUser provides code:
def calculate_discount(price, discount_percent):
if discount_percent < 0 or discount_percent > 100:
raise ValueError("Discount must be between 0 and 100")
return price * (1 - discount_percent / 100)Synthesized assertions:
def test_calculate_discount_normal():
assert calculate_discount(100, 10) == 90.0
assert calculate_discount(50, 20) == 40.0
def test_calculate_discount_zero():
assert calculate_discount(100, 0) == 100.0
def test_calculate_discount_full():
assert calculate_discount(100, 100) == 0.0
def test_calculate_discount_invalid_negative():
with pytest.raises(ValueError, match="between 0 and 100"):
calculate_discount(100, -10)
def test_calculate_discount_invalid_over_100():
with pytest.raises(ValueError, match="between 0 and 100"):
calculate_discount(100, 150)User provides weak test:
def test_sort_list():
result = sort_list([3, 1, 2])
assert result # Only checks if result existsEnhanced assertions:
def test_sort_list():
result = sort_list([3, 1, 2])
# Verify actual sorting behavior
assert result == [1, 2, 3]
assert len(result) == 3
assert isinstance(result, list)
def test_sort_list_empty():
assert sort_list([]) == []
def test_sort_list_already_sorted():
assert sort_list([1, 2, 3]) == [1, 2, 3]
def test_sort_list_duplicates():
assert sort_list([3, 1, 2, 1]) == [1, 1, 2, 3]0f00a4f
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.