Annotations and Attributes of Testing Frameworks


In this post, I will explain frequently used attribute and annotations in various testing frameworks.

It is called attributes in the .NET environment and annotations in Java. We use them to declare information about methods, types, properties and so on.

We will discuss about frequently used ones to run test scenarious properly. You would find comparisons of NUnit, MSTest, xUnit.net and JUnit testing frameworks down below.

NUnit MSTest xUnit.net JUnit Description
[TestFixture]
[TestClass] Indicates that the class has test methods.
[Test] [TestMethod] [Fact] @Test Marks a test case.
[OneTimeSetUp] [ClassInitialize] IClassFixture @BeforeClass The one time triggered method before test cases start.
[OneTimeTearDown] [ClassCleanup] IClassFixture @AfterClass The one time triggered method after test cases end.
[SetUp] [TestInitialize] Constructor @Before Triggered before every test case.
[TearDown] [TestCleanup] IDisposable.Dispose @After Triggered after every test case.
[Ignore] [Ignore] [Fact(Skip=”reason”)] @Ignore Ignores the test case.
[Category(“”)] [TestCategory(“”)] [Trait(“Category”, “”)] @Category(*.class) Categorizes the test cases or classes.

There is a little difference between them except that the xUnit framework. xUnit prefers inheritance for the ones that it doesn’t want to be used very often.

Category separation is a best practice on testing because you could see your test cases by its category on your test runner tool or run them in a Continuous Integration application seperately.

If you don’t want to run a test temporarily you could use ignore attribute. Your test runner tool will skip that test and show it with the provided message.

annotations

Display on Test Explorer

testingignorejenkins

Display on Jenkins CI Test Coverage Report

Let’s build a test project to see the order of the attributes precisely.

Create a new Class Library project and a method to test like the one below.

Add an Unit Test Project to the Solution and add a reference of the class library project.

Replace the unit test class with the following example.

testingproject

Project’s view

Test output after the test run:

 

javafx

Database Operations in JavaFX

By Onur Baskirt / Apr 1, 2016 / 56 Comments
Before started this section, please check the first article and learn How to Start JAVAFX! http://www.swtestacademy.com/getting-started-with-javafx/ At first, part of JavaFX tutorial series, we created a sample JavaFX project, designed the draft version of the UI and set up an...
rest assured

REST API Testing with Rest Assured

By Onur Baskirt / Mar 8, 2016 / 32 Comments
Outline In this post, I will explain what is API and API testing, what is the difference between SOAP and REST services, and how to test REST APIs with Rest Assured Library. What is API? API stands for Application Programming...
extentreports

How to Write Effective CSS Locators

By Onur Baskirt / Oct 1, 2017 / 0 Comments
Hi all, in this tutorial, I will describe you how to write effective CSS locators to interrogate web elements for your automation projects. As a rule of thumb, your interrogation strategy should be in below order: First try to use...
extentreports

Selenium-11: Execute JavaScript with JavascriptExecutor

By Onur Baskirt / Jan 27, 2016 / 15 Comments
Outline Sometimes we cannot handle some conditions or problems with Webdriver, web controls don't react well against selenium commands. In this kind of situations, we use Javascript. It is useful for custom synchronizations, hide or show the web elements, change...
javafx

Getting Started with JavaFX

By Onur Baskirt / Mar 25, 2016 / 0 Comments
When I started to work in my current position, one of my task is to do manual operations for campaign products  every week. After the second week, I thought that I have to automate this task using a GUI based...
extentreports

How to Write Smart XPath Locators

By Onur Baskirt / Sep 24, 2017 / 4 Comments
Hi all, in this tutorial, I will describe you how to write smart and non-brittle XPath locators. When we write our test scripts, we generally prefer to use id, name, class, etc. these kinds of locators. However, sometimes we could not...
extentreports

Selenium-1: Quick Start to Automation with Selenium WebDriver & JAVA & JUnit & Maven & IntelliJ

By Onur Baskirt / Sep 8, 2015 / 26 Comments
Outline Selenium Webdriver is the most popular open source web test automation framework across wide range of browsers and platforms. In this tutorial you will learn how to do web test automation with Selenium Webdriver and the related tools. Audience...
page object model

Page Object Model with C#

By Ege Aksoz / Jun 18, 2017 / 8 Comments
In the previous tutorial, we’ve taken the initial steps and entered the world of automated testing. We also wrote our first automated test. From this point on, since we are not just going to write one test, we need to...
extentreports

How to Select a Date From DatePicker Using Selenium

By Onur Baskirt / Aug 13, 2016 / 6 Comments
When you need to automate a airway, hotel, or similar websites you need to deal with Datepickers and some times it is a little bit cumbersome to select a specific date on the Datepicker or calendar.  In this post, I...
extentreports

Selenium Webdriver Performance testing with Jmeter and Selenium Grid

By Ozgur Kaya / Aug 9, 2016 / 2 Comments
In this post, we will complete Selenium Webdriver Performance testing scenario using Jmeter and Selenium Grid. 1- Install Java 7 or later If necessary https://java.com/tr/download/ 2- Download latest Jmeter version 3.0 or higher. http://jmeter.apache.org/download_jmeter.cgi 3- Download Jmeter PluginsManager JAR file and...
By | 2017-01-13T21:33:41+00:00 November 1st, 2016|Test Automation, Test Frameworks|0 Comments

Share This Story, Choose Your Platform!

About the Author:

Olcay Bayram
Olcay Bayram is a software enthusiast; currently a developer of e-commerce team of Kariyer.net. Apart from the BSc, he holds a masters in information technologies and has a blog on his own ; http://otomatikmuhendis.com/

Leave A Comment