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
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);
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}")
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());
}
}
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}");
}
}
Configuration Parameters
Name of the practice test component
Must be
"practice_test"Practice test configuration object
Show Configuration Properties
Show Configuration Properties
Array of material IDs to generate questions from
Array of folder IDs containing materials
Types of questions to include:
multiplechoice- Multiple choice questionstruefalse- True/false questionsessay- Essay questionsshortanswer- Short answer questionsfillintheblanks- Fill in the blank questions
Number of questions per test (minimum: 5, maximum: 50)
Test difficulty level:
easy- Basic recall and understandingmedium- Application and analysishard- Synthesis and evaluation
Time limit in minutes (0 for no limit)
Show correct answers after submission
Randomize question order for each attempt
Allow multiple attempts at the test
Minimum passing percentage (0-100)
Response
{
"_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
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
});
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
)
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);
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}");
}
}
Practice Test-Specific Embedding Features
Track test attempts, scores, and allow reviewing past submissions
Embed in Your HTML
<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>