Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the [fact] attribute?

Tags:

c#

I'm sure this is super simple, but I'm clearly not Googling the right thing. In several unit test related blogs, I've seen the attribute [fact] given to several methods, but I can't seem to figure out what this means. Example:

public class SomeClass
{
    [Fact]
    public void Foo()
    {

    }

    [Fact]
    public void Bar()
    {

    }
}
like image 559
jhammond Avatar asked Feb 09 '15 17:02

jhammond


People also ask

What is Fact attribute in C#?

The [Fact] attribute declares a test method that's run by the test runner. From the PrimeService. Tests folder, run dotnet test . The dotnet test command builds both projects and runs the tests.

What is difference between Fact and Theory in xUnit?

Fact vs Theory In an Xunit test class or fixture, there are two kinds of tests: Fact tests and Theory tests. The small, but very important, difference is that Theory tests are parameterized and can take outside input. Fact tests, however, are not parameterized and cannot take outside input.

What is Theory in unit testing?

Remember: The purpose of a unit test is to evaluate the quality of a single unit of code. Some units will accept arguments, some units will not, some units will return values, others will not. Whatever the case may be, your unit test should evaluate all cases. A single unit of code will rarely have a single test.

What is xUnit testing in C #?

Besides the InlineData attribute, xUnit provides you with other ways to define data for theories, like ClassData , where the data source is a class implementing the IEnumerable interface, and MemberData , where the data source is a property or a method.

What are attribute attributes and why are they important?

Attributes provide a way of associating information with code in a declarative way. They can also provide a reusable element that can be applied to a variety of targets.

What is an attribute in JavaScript?

Attributes provide a way of associating information with code in a declarative way. They can also provide a reusable element that can be applied to a variety of targets. Consider the [Obsolete] attribute.

What is an attribute in C++?

Attributes provide a powerful method of associating metadata, or declarative information, with code (assemblies, types, methods, properties, and so forth). After an attribute is associated with a program entity, the attribute can be queried at run time by using a technique called reflection.

What is an example of an attribute in literature?

Examples of Attributes. An attribute is defined as a quality or characteristic of a person, place, or thing. Real life individuals and fictional characters possess various attributes. For example, someone might be labeled beautiful, charming, funny, or intelligent.


1 Answers

It belongs to the xUnit unit testing framework.

It says that the method is a unit test.

like image 118
DrKoch Avatar answered Oct 21 '22 09:10

DrKoch