# Testing Strategy {#testing-strategy}


Unit, integration, and end-to-end testing approaches for Ever Gauzy.


## Test Pyramid {#test-pyramid}






```mermaid
graph TB
    A["E2E Tests (few)"] --> B["Integration Tests (some)"]
    B --> C["Unit Tests (many)"]
```






## Unit Tests {#unit-tests}


Unit tests verify individual functions, services, and pipes.


### Running {#running}


```bash
# Run all unit tests
yarn test

# Run with coverage
yarn test --coverage

# Watch mode
yarn test --watch
```


### Example: Service Test {#example-service-test}


```typescript
describe("EmployeeService", () => {
  let service: EmployeeService;
  let repository: MockRepository<Employee>;

  beforeEach(async () => {
    const module = await Test.createTestingModule({
      providers: [
        EmployeeService,
        { provide: getRepositoryToken(Employee), useClass: MockRepository },
      ],
    }).compile();

    service = module.get<EmployeeService>(EmployeeService);
    repository = module.get(getRepositoryToken(Employee));
  });

  it("should find all employees", async () => {
    const employees = [{ id: "1", name: "John" }];
    repository.find.mockResolvedValue(employees);

    const result = await service.findAll();
    expect(result).toEqual(employees);
  });
});
```


## Integration Tests {#integration-tests}


Integration tests verify API endpoints with a real database:

```typescript
describe("EmployeeController (e2e)", () => {
  let app: INestApplication;

  beforeAll(async () => {
    const module = await Test.createTestingModule({
      imports: [AppModule],
    }).compile();

    app = module.createNestApplication();
    await app.init();
  });

  it("/api/employee (GET)", () => {
    return request(app.getHttpServer())
      .get("/api/employee")
      .set("Authorization", `Bearer ${token}`)
      .expect(200)
      .expect((res) => {
        expect(res.body.items).toBeInstanceOf(Array);
      });
  });
});
```


## Frontend Tests {#frontend-tests}


```bash
# Angular component tests
yarn nx test gauzy --watch

# Specific test file
yarn nx test gauzy --testPathPattern=task.component.spec.ts
```


## Related Pages {#related-pages}


- [E2E Testing](https://sourcey-gauzy.pages.dev/development/e2e-testing/index.md) — end-to-end testing
- [API Testing](https://sourcey-gauzy.pages.dev/development/api-testing/index.md) — API test patterns
- [Coding Standards](https://sourcey-gauzy.pages.dev/development/coding-standards/index.md) — code quality
