> ## Documentation Index
> Fetch the complete documentation index at: https://www.studyfetch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Practice Test

> Customizable practice tests with various question types

## Overview

The Practice Test component creates comprehensive tests from your study materials with multiple question types, difficulty levels, and customizable settings. Perfect for exam preparation and knowledge assessment.

## Creating a Practice Test Component

<CodeGroup>
  ```javascript JavaScript theme={null}
  import StudyfetchSDK from '@studyfetch/sdk';

  const client = new StudyfetchSDK({
    apiKey: 'your-api-key',
    baseURL: 'https://studyfetchapi.com',
  });

  const testComponent = await client.v1.components.create({
    name: 'Biology Midterm Practice',
    type: 'practice_test',
    config: {
      materials: ['mat-123', 'mat-456'],
      folders: ['folder-789'],
      questionTypes: ['multiplechoice', 'truefalse', 'shortanswer'],
      questionsPerTest: 25,
      difficulty: 'medium',
      timeLimit: 45,
      showCorrectAnswers: true,
      randomizeQuestions: true,
      allowRetakes: true,
      passingScore: 75
    }
  });

  console.log('Practice test component created:', testComponent._id);
  ```

  ```python Python theme={null}
  from studyfetch_sdk import StudyfetchSDK

  client = StudyfetchSDK(
      api_key="your-api-key",
      base_url="https://studyfetchapi.com",
  )

  test_component = client.v1.components.create(
      name="Biology Midterm Practice",
      type="practice_test",
      config={
          "materials": ["mat-123", "mat-456"],
          "folders": ["folder-789"],
          "questionTypes": ["multiplechoice", "truefalse", "shortanswer"],
          "questionsPerTest": 25,
          "difficulty": "medium",
          "timeLimit": 45,
          "showCorrectAnswers": True,
          "randomizeQuestions": True,
          "allowRetakes": True,
          "passingScore": 75
      }
  )

  print(f"Practice test component created: {test_component._id}")
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.client.StudyfetchSdkClient;
  import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
  import com.studyfetch.javasdk.models.v1.components.ComponentResponse;
  import com.studyfetch.javasdk.models.v1.components.ComponentCreateParams;

  public class CreatePracticeTestComponent {
      public static void main(String[] args) {
          StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
              .fromEnv()
              .baseUrl("https://studyfetchapi.com")
              .build();

          ComponentCreateParams params = ComponentCreateParams.builder()
              .name("Biology Midterm Practice")
              .type(ComponentCreateParams.Type.PRACTICE_TEST)
              .config(ComponentCreateParams.Config.PracticeTestConfigDto.builder()
                  .materials(List.of("mat-123", "mat-456"))
                  .folders(List.of("folder-789"))
                  .questionTypes(List.of("multiplechoice", "truefalse", "shortanswer"))
                  .questionsPerTest(25)
                  .difficulty(ComponentCreateParams.Config.PracticeTestConfigDto.Difficulty.MEDIUM)
                  .timeLimit(45)
                  .showCorrectAnswers(true)
                  .randomizeQuestions(true)
                  .allowRetakes(true)
                  .passingScore(75)
                  .build())
              .build();

          ComponentResponse component = client.v1().components().create(params);
          System.out.println("Practice test component created: " + component._id());
      }
  }
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.Components;
  using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;

  public class CreatePracticeTestComponent
  {
      public static async Task CreatePracticeTest()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          var testComponent = await client.V1.Components.Create(new()
          {
              Name = "Biology Midterm Practice",
              Type = StudyfetchSDK.Models.V1.Components.ComponentCreateParamsProperties.Type.PracticeTest,
              Config = new StudyfetchSDK.Models.V1.Components.ComponentCreateParamsProperties.ConfigProperties.PracticeTestConfigDto()
              {
                  QuestionTypes = new List<string> { "multiple_choice", "true_false" },
                  Materials = new List<string> { "mat-123", "mat-456" }
              }
          });

          Console.WriteLine($"Practice test component created: {testComponent._ID}");
      }
  }
  ```
</CodeGroup>

## Configuration Parameters

<ParamField body="name" type="string" required>
  Name of the practice test component
</ParamField>

<ParamField body="type" type="string" required>
  Must be `"practice_test"`
</ParamField>

<ParamField body="config" type="object" required>
  Practice test configuration object

  <Expandable title="Configuration Properties">
    <ParamField body="materials" type="array" required>
      Array of material IDs to generate questions from
    </ParamField>

    <ParamField body="folders" type="array">
      Array of folder IDs containing materials
    </ParamField>

    <ParamField body="questionTypes" type="array" required>
      Types of questions to include:

      * `multiplechoice` - Multiple choice questions
      * `truefalse` - True/false questions
      * `essay` - Essay questions
      * `shortanswer` - Short answer questions
      * `fillintheblanks` - Fill in the blank questions
    </ParamField>

    <ParamField body="questionsPerTest" type="integer" default="10">
      Number of questions per test (minimum: 5, maximum: 50)
    </ParamField>

    <ParamField body="difficulty" type="string" default="medium">
      Test difficulty level:

      * `easy` - Basic recall and understanding
      * `medium` - Application and analysis
      * `hard` - Synthesis and evaluation
    </ParamField>

    <ParamField body="timeLimit" type="integer" default="0">
      Time limit in minutes (0 for no limit)
    </ParamField>

    <ParamField body="showCorrectAnswers" type="boolean" default="true">
      Show correct answers after submission
    </ParamField>

    <ParamField body="randomizeQuestions" type="boolean" default="true">
      Randomize question order for each attempt
    </ParamField>

    <ParamField body="allowRetakes" type="boolean" default="true">
      Allow multiple attempts at the test
    </ParamField>

    <ParamField body="passingScore" type="integer" default="70">
      Minimum passing percentage (0-100)
    </ParamField>
  </Expandable>
</ParamField>

## Response

```json theme={null}
{
  "_id": "comp_789ghi",
  "name": "Biology Midterm Practice",
  "type": "practice_test",
  "status": "active",
  "config": {
    "materials": ["mat-123", "mat-456"],
    "folders": ["folder-789"],
    "questionTypes": ["multiplechoice", "truefalse", "shortanswer"],
    "questionsPerTest": 25,
    "difficulty": "medium",
    "timeLimit": 45,
    "showCorrectAnswers": true,
    "randomizeQuestions": true,
    "allowRetakes": true,
    "passingScore": 75
  },
  "createdAt": "2024-01-15T10:00:00Z",
  "updatedAt": "2024-01-15T10:00:00Z",
  "organizationId": "org_456def",
  "statistics": {
    "totalAttempts": 0,
    "averageScore": null
  }
}
```

## Embedding This Component

Once you've created a Practice Test component, you can embed it on your website using the embedding API.

### Generate Embed URL

<CodeGroup>
  ```javascript JavaScript theme={null}
  const embedResponse = await client.v1.components.generateEmbed(testComponent._id, {
    // User tracking
    userId: 'user-456',
    studentName: 'Jane Smith',  // Student name for display
    groupIds: ['class-101', 'class-102'],
    sessionId: 'session-789',
    
    // Practice Test-specific features
    features: {
      enableHistory: true
    },
    
    // Dimensions
    width: '100%',
    height: '700px',
    
    // Token expiry
    expiryHours: 24
  });
  ```

  ```python Python theme={null}
  embed_response = client.v1.components.generateEmbed(
      component_id=test_component._id,
      userId="user-456",
      student_name="Jane Smith",  # Student name for display
      groupIds=["class-101", "class-102"],
      sessionId="session-789",
      features={
          "enableHistory": True
      },
      width="100%",
      height="700px",
      expiryHours=24
  )
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.client.StudyfetchSdkClient;
  import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
  import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedParams;
  import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedResponse;

  StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
      .fromEnv()
      .baseUrl("https://studyfetchapi.com")
      .build();

  ComponentGenerateEmbedParams params = ComponentGenerateEmbedParams.builder()
      .id(testComponent._id())
      // User tracking
      .userId("user-456")
      .studentName("Jane Smith")  // Student name for display
      .groupIds(List.of("class-101", "class-102"))
      .sessionId("session-789")
      
      // Practice Test-specific features
      .features(ComponentGenerateEmbedParams.Features.builder()
          .enableHistory(true)
          .build())
      
      // Dimensions
      .width("100%")
      .height("700px")
      
      // Token expiry
      .expiryHours(24)
      .build();

  ComponentGenerateEmbedResponse embedResponse = client.v1().components()
      .generateEmbed(params);
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.Components;
  using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;

  public class GeneratePracticeTestEmbed
  {
      public static async Task GenerateEmbed()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          var embedResponse = await client.V1.Components.GenerateEmbed(new()
          {
              ID = "component_123abc", // Replace with your component ID
              UserID = "user-456",
              StudentName = "Jane Smith",  // Student name for display
              GroupIDs = new List<string> { "class-101", "class-102" },
              Width = "100%",
              Height = "700px"
          });

          Console.WriteLine($"Embed URL: {embedResponse.EmbedURL}");
          Console.WriteLine($"Token: {embedResponse.Token}");
      }
  }
  ```
</CodeGroup>

### Practice Test-Specific Embedding Features

<ParamField body="features.enableHistory" type="boolean" default="true">
  Track test attempts, scores, and allow reviewing past submissions
</ParamField>

### Embed in Your HTML

```html theme={null}
<iframe 
  src="https://embed.studyfetch.com/component/comp_789ghi?token=..."
  width="100%"
  height="700px"
  frameborder="0"
  style="border: 1px solid #e5e5e5; border-radius: 8px;">
</iframe>
```
