2

I am trying to run the test from the internal class and I am getting error:

UTA001: TestClass attribute defined on non-public class

How can I run tests of internal classes using VS and vstest.console.exe?

EDIT: Here is my class and test:

[TestClass]
internal class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        string test = "Test Test";
        var res = test is IEnumerable;
    }
}
Dilshod K
  • 2,924
  • 1
  • 13
  • 46
  • Does this answer your question? [C# "internal" access modifier when doing unit testing](https://stackoverflow.com/questions/358196/c-sharp-internal-access-modifier-when-doing-unit-testing) – jtabuloc Dec 09 '20 at 06:21
  • @jtabuloc My internal class is located in my test project. It couldn't help – Dilshod K Dec 09 '20 at 06:24
  • 1
    Why you don't want the test class to be public? – Chetan Dec 09 '20 at 07:54
  • 1
    You can use NUnit framework. `TestFixture` attribute of NUnit can be used with `internal` test class – Chetan Dec 09 '20 at 07:56

1 Answers1

1

Add the following attribute to your Test Assembly:

[assembly: DiscoverInternals]

Documentation.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
LarHei
  • 11
  • 2