Quiz 2
Registry Synced

Learning Objectives

161 words
1 min read

Reading compass

Now · Step 1: Backend Tests

Learning Objectives

  • Write unit and integration tests
  • Debug API endpoints
  • Handle edge cases

Step 1: Backend Tests

python
# tests/test_api.py
import unittest
from app import app, db
from models import Post
class TestAPI(unittest.TestCase):
    def setUp(self):
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        self.client = app.test_client()
    def test_create_post(self):
        response = self.client.post('/api/posts', json={
            'title': 'Test', 'content': 'Test content'
        })
        self.assertEqual(response.status_code, 201)
        self.assertIn('id', response.get_json())
    def test_get_posts(self):
        response = self.client.get('/api/posts')
        self.assertEqual(response.status_code, 200)

Step 2: Frontend Tests

jsx
// frontend/src/__tests__/App.test.js
import { render, screen } from '@testing-library/react';
import App from '../App';
test('renders app title', () => {
  render(<App />);
  const title = screen.getByText(/MAD1 Project/i);
  expect(title).toBeInTheDocument();
});
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.