Repository navigation
Testing
Laravex is built for testability. Tests are plain ExUnit modules; the framework provides a Laravex.TestCase base module that boots the application and exposes HTTP helpers mirroring Laravel's TestCase conventions.
Tests live in the tests/ directory (configured as the test_paths in mix.exs):
tests/
├── test_helper.exs # ExUnit.start()
├── test_case.ex # Laravex.TestCase base module
├── Feature/
│ └── example_test.exs # HTTP/integration tests
└── Unit/
└── example_test.exs # Pure unit tests
Test files use the .exs extension and the _test suffix. The test pattern is *_test.exs.
mix test # all tests
mix test tests/Unit/ # a specific directory
mix test tests/Feature/example_test.exs # a single file
mix test tests/Feature/example_test.exs:5 # a specific lineFor verbose output:
mix test --traceBase module for integration / HTTP tests. Use it in a test module with use Laravex.TestCase:
defmodule Tests.Feature.HomeTest do
use Laravex.TestCase, async: false
test "homepage returns 200" do
response = get("/")
assert_status(response, 200)
assert_see(response, "Laravex")
end
endUse
async: falsewhen tests share database state;async: trueis safe for stateless or in-memory tests.
TestCase calls Laravex.Foundation.Server.boot!/0 in setup, which boots the full application stack (config, routes, middleware) before each test.
# GET request — returns a %Laravex.Http.Response{}
response = get("/posts/1")
response = get("/api/user", %{"Authorization" => "Bearer token"})
# Assertions
assert_status(response, 200)
assert_see(response, "expected text") # checks response.bodyFor pure unit tests that do not need the HTTP stack, use ExUnit.Case directly:
defmodule Tests.Unit.HashTest do
use ExUnit.Case, async: true
test "hashes and verifies a password" do
hashed = Laravex.Hashing.Hash.make("secret")
assert Laravex.Hashing.Hash.check("secret", hashed)
refute Laravex.Hashing.Hash.check("wrong", hashed)
end
endFeature tests exercise the full request lifecycle through Laravex.Http.Kernel:
defmodule Tests.Feature.PostTest do
use Laravex.TestCase, async: false
test "can view a published post" do
user = Database.Factories.UserFactory.create()
post = Database.Factories.PostFactory.create(%{
"user_id" => user.id,
"published" => true
})
response = get("/posts/#{post.id}")
assert_status(response, 200)
assert_see(response, post.title)
end
test "health endpoint is up" do
response = get("/up")
assert_status(response, 200)
end
endTests use the same SQLite database as development by default. Reset it before a run with:
./artisan migrate:fresh
./artisan db:seed
mix testFor fully isolated test runs, set a separate database path in config/test.exs:
# config/test.exs
%{
"database" => %{
"connections" => %{
"sqlite" => %{"database" => "database/test.sqlite"}
}
}
}Use Eloquex-Factories to create model fixtures:
user = Database.Factories.UserFactory.create()
post = Database.Factories.PostFactory.create_state(:published, %{"user_id" => user.id})- Eloquex-Factories — Generating test data
- Seeding — Seeding the test database
- Database — SQLite connection and test database config
Laravex — Laravel-faithful application skeleton & runtime for Elixir.
GitHub
·
Docs
·
Limitations
·
Laravel Docs
Not affiliated with Laravel LLC or the Elixir core team. Built to feel like Laravel on the BEAM.
- Home
- Installation
- Configuration
- Directory-Structure
- Request-Lifecycle
- Service-Container
- Service-Providers
- Deployment
- Routing
- Middleware
- CSRF-Protection
- Controllers
- Requests
- Responses
- Views
- Blade-Templates
- Asset-Bundling
- Session
- Validation
- Error-Handling
- Logging
- Artisan-Console
- Broadcasting
- Cache
- Collections
- Events
- File-Storage
- Helpers
- HTTP-Client
- Localization
- Notifications
- Pipeline
- Queues
- Rate-Limiting
- Strings
- Task-Scheduling