Introduction Flashcards
What’s triple A in unit tests?
It’s a basic test structure. Every test has the same structure, which is: Assert, Act and Assert.
What’s type safe on c#?
Means that the compiler guarantees the types you’re using within your app. This is not satisfied when you use “MyProperty” kind of access.
What’s classic and constraint-based asserts on unit tests?
Classic matches the value, e.g: Assert.Equals(expected, actual). Constraint is based on a prose: Assert.That(1, Is.EqualTo(actualValue).
What’s a lambda expression?
A nameless function.
How to test a float value in c# / nunit?
Use the within method.
One example of type safe assert and one regular
Use matches method for type-safe lambda expressions and Property(“MyPropName”) for a non-type-safe.
What’s the four most common constraint assertions?
Is, That, Does and Has (for lists)
Is it ok having multiple asserts in the same test?
Yes, if they are asserting the same behavior.
How to comment out a code block?
ctrl + k + ctrl +c
How to ignore a test in unit?
Use the Ignore attribute and define a reason message
How to separate tests in tests or category? And how to filter them?
Using Category attribute. Ignore via visual studio or –filter in dotnet test
What’s the basic test execution flow of the framework?
ctor, one-time setup, setup, test, tear down, one-time teardown and dispose
What are the principles of good unit tests?
Fast, Repeatable, Isolated, Trustworthy and Valuable
How to reuse the same test method but with different data?
Via TestCase attribute and defining the input values, then allowing the method below to receive the input values and the expected value.
What’s data-driven-tests?
Is a way to test using different set of input values for the same test method.
Can you assert the expected value outside the method?
Yes. Via ExpectedResult property within the TestCase attribute.
How to centralize test case data?
By creating a class and method that returns an IEnumerable containing TestCaseData items. Then by specifying a TestCaseSource in the test method.
In which cases combinatorial and sequential test cases are useful?
To test all sort of combinations of values and ensure they won’t raise an exception, for example.
Is it possible to centralize test case data in files?
Yes, you can create a csv file and then create the logic to read it and generate TestCaseData itens.