Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to execute a single ExUnit test #34

Closed
nelsonic opened this issue Feb 19, 2017 · 6 comments
Closed

Trying to execute a single ExUnit test #34

nelsonic opened this issue Feb 19, 2017 · 6 comments

Comments

@nelsonic
Copy link
Member

nelsonic commented Feb 19, 2017

Tried using the code in the book on p.131. (copied verbatim):

defmodule MyTest do
  use ExUnit.Case, async: true

  setup do
    # run some tedious setup code
    :ok
  end

  test "pass" do
    assert true
  end

  test "fail" do
    assert false
  end
end

tried to run the individual file in the terminal.

But got the following error:

(RuntimeError) cannot use ExUnit.Case without starting the ExUnit application, please call ExUnit.start() or explicitly start the :ex_unit app

Screenshot:
image

Looked at https://hexdocs.pm/ex_unit/ExUnit.Case.html but no luck.
Also looked at https://elixirschool.com/lessons/basics/testing and didn't get much enlightenment...

I'm trying to execute a single test file ...
looked at: http://stackoverflow.com/questions/26150146/how-can-i-make-mix-run-only-specific-tests-from-my-suite-of-tests
Tried mix test basic-test.exs and mix test --only basic-test.exs
image

This question might be more appropriate in https://github.com/dwyl/learn-elixir ...
but I figured that given its from the "Programming Phoenix" book, other people might find it here....

@nelsonic
Copy link
Member Author

Didn't succeed in running the single test. (decided to move on with the Phoenix tutorial ...)
But would still like to know if/how to do it if anyone else fiugres it out.
if you know how to run a single test file, please share/comment. thanks! 👍

@samhstn
Copy link
Member

samhstn commented Feb 19, 2017

I managed to run tests by following this

You need to create a test_helper.exs file (these are generated from running mix new .)
The file is automatically run when you run tests and it includes the ExUnit.start() script

To get a single test running do the following:

cd Desktop
mix new testing
cd testing
touch test/basic-test.exs

paste the above into test/basic-test.exs

Then run:

mix test test/basic-test.exs

And it should work

@nelsonic
Copy link
Member Author

@Shouston3 yeah, I should have clarified that I was trying to avoid creating a new project using mix but you're right, that's the simplest way of making progress with this. 👍
(thanks for being on-the-ball and taking the time to reply. hope you're having a good weekend.)

@samhstn
Copy link
Member

samhstn commented Feb 19, 2017

In that case you could run:

elixir -e "ExUnit.start()" -r basic-test.exs

Having a good weekend thanks, hope you're having a great one too

@samhstn
Copy link
Member

samhstn commented Feb 20, 2017

@nelsonic happy for you to close this 👍

@nelsonic
Copy link
Member Author

@Shouston3 my next PR will close it. 👍

@iteles iteles closed this as completed in a034625 Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants