Editing
Functional Testing in Elixir with ExUnit
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Writing Functional Tests with ExUnit === ExUnit provides a clean and expressive syntax for writing functional tests in Elixir. Let's look at an example: ```elixir defmodule MyModuleTest do use ExUnit.Case test "addition is correct" do result = MyModule.add(2, 3) assert result == 5 end end ``` In the above example, we define a test case module using `defmodule` and `use ExUnit.Case`. Inside the module, we define a test using the `test` macro. Within the test block, we call the function we want to test and use the `assert` macro to verify if the result is as expected. ExUnit provides various assertion macros such as `assert`, `assert_equal`, `assert_raise`, etc., which can be used to validate different aspects of the code being tested.
Summary:
Please note that all contributions to Elixir Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Elixir Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information