https://github.com/hissssst/mix_tester
Tiny tool to automate mix project's testing
https://github.com/hissssst/mix_tester
Last synced: 2 months ago
JSON representation
Tiny tool to automate mix project's testing
- Host: GitHub
- URL: https://github.com/hissssst/mix_tester
- Owner: hissssst
- License: bsd-2-clause
- Created: 2023-06-04T21:58:56.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-31T12:04:49.000Z (over 1 year ago)
- Last Synced: 2024-11-08T14:51:51.952Z (11 months ago)
- Language: Elixir
- Size: 15.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# MixTester
Tiny project for testing mix tasks and anything related to project management and code generation tooling
## Features
* Real mix project management experience with `new` flags and other stuff
* Application env configuration
* Dependency list and other mix.exs configuration
* Handy and simple helpers for common commands
* ExUnit's async friendly## Usage
```elixir
defmodule AwesomeTask do
use ExUnit.Case, async: truesetup do
deps = [ {:awesome_task, path: File.cwd!()} ]
configuration = %{{:awesome_task, :year} => 2007}# Creates project with `mix new my_project --sup`
# Which has `awesome_task` as a dependency
# And configuration where `config.exs` has
project =
MixTester.setup(
name: "my_project",
new: "--sup",
application_env: %{
"config" => configuration
},
project: [
deps: deps
]
)# Creates the test file
MixTester.write_ast(project, "test/my_project_test.exs", quote do
defmodule MyProjectTest do
use ExUnit.Case, async: truetest "Just works" do
assert 2007 == AwesomeModule.what_year_is_today()
end
end
end)# Cleanup the tmp dir
on_exit(fn -> MixTester.cleanup(project) end)
{:ok, project: project}
endtest "My awesome task", %{project: project} do
# Run the task we are testing
assert {_, 0} = MixTester.mix_cmd(project, "awesome")# Run the test written above and check if it's run successfully
assert {_, 0} = MixTester.mix_cmd(project, "test")
end
end
```Check out the documentation for more practical use cases:
https://hexdocs.pm/mix_tester## Installation
```elixir
def deps do
[
{:mix_tester, "~> 1.0"}
]
end
```