# Plugin Testing {#plugin-testing}


Test your custom Gauzy plugins.


## Unit Testing Plugins {#unit-testing-plugins}


```typescript
import { Test, TestingModule } from "@nestjs/testing";
import { MyPluginService } from "./my-plugin.service";

describe("MyPluginService", () => {
  let service: MyPluginService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [
        MyPluginService,
        {
          provide: "MY_PLUGIN_CONFIG",
          useValue: {
            apiKey: "test-key",
            endpoint: "https://test.api.com",
            enabled: true,
          },
        },
      ],
    }).compile();

    service = module.get(MyPluginService);
  });

  it("should be defined", () => {
    expect(service).toBeDefined();
  });

  it("should process data", async () => {
    const result = await service.process({ input: "test" });
    expect(result).toBeDefined();
  });
});
```


## Integration Testing {#integration-testing}


```typescript
describe("MyPlugin Integration", () => {
  let app: INestApplication;

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

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

  it("should register plugin endpoint", async () => {
    await request(app.getHttpServer()).get("/api/my-plugin/status").expect(200);
  });

  afterAll(async () => {
    await app.close();
  });
});
```


## Mocking External Services {#mocking-external-services}


```typescript
const mockExternalApi = {
  fetchData: jest.fn().mockResolvedValue({ success: true }),
  sendNotification: jest.fn().mockResolvedValue(true),
};

// In module
providers: [{ provide: ExternalApiService, useValue: mockExternalApi }];
```


## Related Pages {#related-pages}


- [Plugin Dev Quickstart](https://sourcey-gauzy.pages.dev/plugins-built-in/plugin-dev-quickstart/index.md) — getting started
- [Unit Testing Guide](https://sourcey-gauzy.pages.dev/testing/unit-testing/index.md) — unit tests
- [E2E Testing Guide](https://sourcey-gauzy.pages.dev/testing/e2e-testing/index.md) — E2E tests
