1

I have a problem with executing test from nunit3-console. I need to pass parameters to TestFixture constructor, but i want to call an specific Test. In my fixture i have two different constructors and one method without arguments. Now i call this cdm:

  1. nunit3-console --params username=u1;password=p1 --test namespace.class.Test1 Tests.dll

I think, now nunit try to pass this 2 parameters to my test, but i want to pass it into constructor, which have

  1. [TestFixtureSource(typeof(TestFixtureSource), "GetParameters")]

When i call an cmd with --where "class='TestFixtureClassName'"clause parameters are passed into testfixture constructor, but it runs all tests inside this fixture.


In example

namespace TestNamespace
{
[TestFixtureSource("GetTestFixtureSource")]
public class TestFixture
{
private int _a;
private int _b;
TestFixture()
{
_a = 8;
_b = 10;
}
TestFixture(int a, int b)
{
_a = a;
_b = b;
}
[Test]
public void Test()
{
//test1 body
}
[Test]
public void Test2()
{
//test2 body
}
[Test]
public void Test3()
{
//test3 body
}
}
}

Now in command prompt i call this line:

  1. nunit3-console --params a=80;b=100 --test TestNamespace.TestFixture.Test Tests.dll

Result of this line is that selenium tries to find method Test with 2 arguments. But when u call nunit-console like this:

  1. nunit3-console --params a=80;b=100 --where class='TestFixture' Tests.dll

It finds suitable constructor with 2 arguments and call it, but runs all Tests inside this Fixture. Now, what i want to achieve is run single test, but pass --params to suitable constructor of TestFixture.

Hope now i presented it more clearly for you.

ozyrys1994
  • 21
  • 2
  • Is there a reason you want to do this with parameters rather than app.config files? – mjwills Jun 05 '17 at 13:01
  • I run this test from visual studio without parameters, but they are also runned by cmd from TestComplete, on two diffrent databases, two different urls (they are personalized for each user) – ozyrys1994 Jun 05 '17 at 13:46

1 Answers1

0

Your description could use a bit more code to make clear what you are doing.

However, from what you say, it sounds as if the run parameters are being passed and used in the fixture constructor without problem. Am I misunderstanding something?

Which tests get run is an entirely separate matter. If you use a --where clause that specifies the class name, then you are telling the runner to run all the tests in that class. But your description says there is only one test method. Please make your problem clearer in your description by showing what you are doing in the test code, what you hope will happen and what actually happens.

As you see... I started to answer but realized I don't understand the problem, so you can consider this as a long comment. I'll answer after you update the question.

Charlie
  • 12,928
  • 1
  • 27
  • 31