Define a global variable in Nunit SetUpFixture class

gt.guybrush

Hi I have to use a variable in all my tests make with Nunit

SimpleContainer container = new SimpleContainer();  

so I try to put this definition in the setup class:

[SetUpFixture]
public static class TestSetup
{
    public static SimpleContainer container = new SimpleContainer();    
}

I use static class for ability to write:

IMyClass myClassExpected = (IMyClass)TestSetup.container.GetInstance(typeof(IMyClass), null);

but after running test I get this error: "TestSetup is an abstract class"

I simply don't understand where is the problem

Arran

I would suggest you not bother with having a static instance, and instead, use inheritance.

So create a base class, which includes your object:

public class BaseTestFixture
{
    public SimpleContainer Container { get { return new SimpleContainer(); } }
}   

Have all your tests inherit from this:

public class GoogleTests : BaseTestFixture
{
    [Test]
    public void GoToGoogle()
    {
        Container.GetInstance(.....);
    }
}   

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Inheritance of SetupFixture of a base class from different projects (nunit)

From Dev

How to define Global variable outside class?

From Java

Define global variable with webpack

From Dev

Define global variable in JQuery

From Java

Define global variable in a JavaScript function

From Dev

How to define global variable for Twig

From Dev

Define global variable inside a function

From Dev

Define global variable inside a function

From Dev

how to define Global variable in codeigniter?

From Dev

View to global class variable?

From Dev

global variable in class php

From Dev

Inner class with global variable

From Dev

Global variable (Class)

From Dev

python unittests define a global webdriver variable

From Dev

How to define global variable inside a function?

From Dev

How to define a global variable(value) in codeIgniter

From Dev

Define global variable using function argument in R

From Dev

How to define a global variable in LLVM and use it in C?

From Dev

How to define global variable in PL/SQL in Oracle?

From Dev

C - How to define a global variable using a loop?

From Dev

How to define global variable inside a function?

From Dev

How to define global template variable in AngularDart

From Dev

Unable to define a global variable in C++

From Dev

define variable of global scope in local scope

From Dev

Trying to define GLOBAL variable not working PHP

From Dev

python unittests define a global webdriver variable

From Dev

CakePHP 3 : Define global contant variable

From Dev

how to define a global variable inside linux kernel?

From Dev

Kotlin Set Global Variable in Global Class