Unknown dependency error when trying to run a single test

Hi

I am trying to run a single test. I get the following error.

** (Mix) Unknown dependency test/resources/rule_test.exs for environment test

I tried searching but I could not find any hints.

Elixir version: Elixir (1.15.6)
Erlang version: Erlang 26

-Srikanth

Hello and welcome…

You need to provide more information. For example, this rule_test.exs, or config/test.exs.

Is it Phoenix? a simple mix project? Nothing can be deduced with just the information You gave.

1 Like

Hi

My bad it is a phoenix project. It is an exunit test.
I was running the test using this command

MIX_ENV=test mix test test/reserve/resources/rule_test.exs  

It is not equivalent to…

Which one is right?

I meant You should show the content of the files…

We still cannot guess what is wrong

Ok here is the code. It just testing API end point.
The whole point is, if I run

MIX_ENV=test mix test

everything works. I am not able to run a single test. I am not able to figure out why.
I guess I have to go back in commits to figure it out.

defmodule RuleTest do
  use ExUnit.Case
  use Fancy.DataCase, async: false
  use FancyWeb.ConnCase
  import ApiTestHelper
  alias FancyWeb.Support.Factory, as: Factory

  @url "/api/reservation/rules"

  setup _context do
    %{user_id: user_id, token: token} = Factory.make_user_and_token(email: "rule")

    on_exit(fn ->
      Factory.destroy_user(user_id)
    end)

    %{token: token}
  end

  test ~c"GET /rules", %{token: token} do
    get_test?(
      token,
      @url
    )
  end

  test ~c"POST /rules", %{token: token} do
    get_fn = fn -> Logger.info("get fn") end

    post_test?(
      token,
      @url,
      %{
        data: %{
          type: "rule",
          attributes: %{
            name: "New rule"
          }
        }
      },
      %{
        data: %{
          type: "rule",
          attributes: %{
            name: "New rule1"
          }
        }
      },
      "name",
      "New rule",
      "New rule1",
      get_fn
    )
  end
end

I think You are mixing api calls with the structure of the test folder…

You should probably use test/fancy_web/api/…_controller_test.exs

But You are testing directly the api with /api/reservation/rules…

If You have the tree command, You could use tree test to see the hierarchy inside your tests.

Also mix test is working

But You don’t use the right path to the test file… it has nothing to do with the path of your api.

What You need to provide is the path to the test file, which should look like this test/somewhere/…_test.exs

or…

mix test $(find test -name rule_test.exs)

Hi @kokolegorille

I have found the issue. The issue was not with the path, the path was right. I have intentionally strip path for official reasons. It was with setup scripts. I have removed the ecto drop command from the scripts it was causing the issue. Found it.

Thanks for helping.