dwyl / learn-phoenix-framework

:fire: Phoenix is the web framework without compromise on speed, reliability or maintainability! Don't settle for less. :rocket:
648 stars 45 forks source link

Trying to execute a single ExUnit test #34

Closed nelsonic closed 7 years ago

nelsonic commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

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 commented 7 years ago

@nelsonic happy for you to close this πŸ‘

nelsonic commented 7 years ago

@shouston3 my next PR will close it. πŸ‘