SlideShare une entreprise Scribd logo
1  sur  20
UnitTesting
Building Rock-Solid Software
Svetlin Nakov
Telerik Software Academy
http://academy.telerik.com
ManagerTechnicalTraining
http://www.nakov.com
What is UnitTesting?
UnitTest – Definition
A unit test is a piece of code written by
a developer that exercises a very small,
specific area of functionality of the code
being tested.
“Program testing can be used to show the
presence of bugs, but never to show their
absence!”
Edsger Dijkstra, [1972]
UnitTest – Example
int sum(int[] array) {
int sum = 0;
for (int i=0; i<array.length; i++)
sum += array[i];
return sum;
}
void testSum() {
if (sum(new int[]{1,2}) != 3)
throw new TestFailedException("1+2 != 3");
if (sum(new int[]{-2}) != -2)
throw new TestFailedException("-2 != -2");
if (sum(new int[]{}) != 0)
throw new TestFailedException("0 != 0");
}
UnitTesting – Some Facts
 Tests are pieces of code (small programs)
 In most cases unit tests are written by
developers, not by QA engineers
 Unit tests are released into the code repository
(TFS / SVN / Git) along with the code they test
 Unit testing framework is needed
 Visual StudioTeamTest (VSTT)
 NUnit, MbUnit, Gallio, etc.
5
UnitTesting
Frameworks & JUnit
UnitTesting Frameworks
 JUnit
 The first popular unit testing framework
 Based on Java, written by Kent Beck & Co.
 Similar frameworks have been developed for a
broad range of computer languages
 NUnit – for C# and all .NET languages
 cppUnit, jsUnit, PhpUnit, PerlUnit, ...
 Visual StudioTeamTest (VSTT)
 Developed by Microsoft, integrated inVS
7
UnitTesting Frameworks
 JUnit – the first unit testing framework
 www.junit.org
 Based on Java
 Developed by Erich Gamma and Kent Beck
 Unit testing frameworks have been developed for a
broad range of computer languages
 NUnit – for C#,VB.NET and .NET languages
 cppUnit, DUnit, jsUnit, PhpUnit, PerlUnit, ...
 List of xUnit frameworks can be found at:
http://www.testingfaqs.org/t-unit.html
JUnit – Features
 Test code is annotated using Java 5
annotations
 Test code contains assertions
 Tests are grouped in test fixtures and test
suites
 Several execution interfaces
 Eclipse integrated plug-in
 Console interface:
java org.junit.runner.JUnitCore <test-class>
JUnit – Annotations
 @Test
 Annotates a test case method
 @Before, @After
 Annotates methods called before/after each test
case
 @BeforeClass, @AfterClass
 Annotates methods called one time before and
after all test cases in the class
 @Ignore
 Ignores a test case
10
JUnit – Assertions
 Using org.junit.Assert class
 Assertions check a condition and throw exception if
the condition is not satisfied
 Comparing values
 assertEquals ([message], expected value,
calculated value)
 Comparing objects
 assertNull([message], object)
 assertNotNull([message], object)
 assertSame ([message], expected obj,
calculated obj)
JUnit – Assertions (2)
 Conditions
 assertTrue(condition)
 assertFalse(condition)
 Forced test fail
 fail()
 Expecting exception
 @Test(expected=IndexOutOfBoundsExcept
ion.class)
 Java class that needs unit testing:
JUnit – Example
public class Sumator {
public int sum(int a, int b) {
int sum = a + b;
return sum;
}
public int sum(int... nums) {
int sum = 0;
for (int i = 0; i < nums; i++)
sum += nums[i];
return sum;
}
}
 JUnit based test class (fixture):
JUnit – Example
import org.junit.Test;
import static org.junit.Assert.*;
public class SumatorTest {
@Test
public void testSum() {
Sumator sumator = new Sumator();
int sum = sumator.sum(new int[] {2,3,4});
assertEquals(sum, 9);
}
}
 JUnit text fixture with setup and cleanup:
JUnit – Example
public class SumatorTest {
private Sumator sumator;
@Before public void setUpTestCase() {
this.sumator = new Sumator();
}
@Test public void testSum() {
int sum = sumator.sum(2, 3);
assertEquals(sum, 5);
}
@After public void cleanUpTestCase() {
this.sumator = null;
}
}
Test Suites
 Suits are sets of JUnit test classes
 We can define test suits with annotations:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(value=Suite.class)
@SuiteClasses(value={Test1.class, Test2.class})
public class AllTests {
}
Eclipse and JUnit
 Eclipse has
built-in
support for
integration
with JUnit
 Can create,
run and
debug JUnit
tests
Testing with JUnit
Live Demo
форумпрограмиране,форум уеб дизайн
курсовеи уроци по програмиране,уеб дизайн – безплатно
програмиранеза деца – безплатни курсове и уроци
безплатенSEO курс -оптимизация за търсачки
уроципо уеб дизайн, HTML,CSS, JavaScript,Photoshop
уроципо програмиранеи уеб дизайн за ученици
ASP.NETMVCкурс – HTML,SQL,C#,.NET,ASP.NETMVC
безплатенкурс"Разработка на софтуер в cloud среда"
BGCoder -онлайн състезателна система -online judge
курсовеи уроци по програмиране,книги – безплатно отНаков
безплатенкурс"Качествен програменкод"
алгоакадемия – състезателно програмиране,състезания
ASP.NETкурс -уеб програмиране,бази данни, C#,.NET,ASP.NET
курсовеи уроци по програмиране– Телерик академия
курсмобилни приложения с iPhone, Android,WP7,PhoneGap
freeC#book, безплатна книга C#,книга Java,книга C#
Дончо Минков -сайт за програмиране
Николай Костов -блог за програмиране
C#курс,програмиране,безплатно
UnitTesting
http://academy.telerik.com
FreeTrainings @Telerik Academy
 C# Programming @Telerik Academy
 csharpfundamentals.telerik.com
 Telerik Software Academy
 academy.telerik.com
 Telerik Academy @ Facebook
 facebook.com/TelerikAcademy
 Telerik Software Academy Forums
 forums.academy.telerik.com

Contenu connexe

Tendances (20)

Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
What is JUnit? | Edureka
What is JUnit? | EdurekaWhat is JUnit? | Edureka
What is JUnit? | Edureka
 
testng
testngtestng
testng
 
Junit
JunitJunit
Junit
 
Junit
JunitJunit
Junit
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
 
xUnit Style Database Testing
xUnit Style Database TestingxUnit Style Database Testing
xUnit Style Database Testing
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
C++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing FrameworkC++ Unit Test with Google Testing Framework
C++ Unit Test with Google Testing Framework
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
 
Unit testing
Unit testingUnit testing
Unit testing
 
Introduction To J unit
Introduction To J unitIntroduction To J unit
Introduction To J unit
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
 
Junit
JunitJunit
Junit
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 

En vedette

Tools for Developers
Tools for DevelopersTools for Developers
Tools for DevelopersSvetlin Nakov
 
Growing a Developer - Svetlin Nakov @ BHRMDA Conference 2012
Growing a Developer - Svetlin Nakov @ BHRMDA Conference 2012Growing a Developer - Svetlin Nakov @ BHRMDA Conference 2012
Growing a Developer - Svetlin Nakov @ BHRMDA Conference 2012Svetlin Nakov
 
Telerik Software Academy - Info Day - August 2012
Telerik Software Academy - Info Day - August 2012Telerik Software Academy - Info Day - August 2012
Telerik Software Academy - Info Day - August 2012Svetlin Nakov
 
5. Подготовка и явяване на ИТ интервю
5. Подготовка и явяване на ИТ интервю5. Подготовка и явяване на ИТ интервю
5. Подготовка и явяване на ИТ интервюSvetlin Nakov
 
Следвай вдъхновението си!
Следвай вдъхновението си!Следвай вдъхновението си!
Следвай вдъхновението си!Svetlin Nakov
 
1. Търсене на работа в ИТ индустрията: процесът
1. Търсене на работа в ИТ индустрията: процесът1. Търсене на работа в ИТ индустрията: процесът
1. Търсене на работа в ИТ индустрията: процесътSvetlin Nakov
 
Свободно образование и споделяне на знания
Свободно образование и споделяне на знанияСвободно образование и споделяне на знания
Свободно образование и споделяне на знанияSvetlin Nakov
 
4. Писане на мотивационно писмо
4. Писане на мотивационно писмо4. Писане на мотивационно писмо
4. Писане на мотивационно писмоSvetlin Nakov
 
Regular Expressions: QA Challenge Accepted Conf (March 2015)
Regular Expressions: QA Challenge Accepted Conf (March 2015)Regular Expressions: QA Challenge Accepted Conf (March 2015)
Regular Expressions: QA Challenge Accepted Conf (March 2015)Svetlin Nakov
 
3. Подготовка на впечатляващо CV
3. Подготовка на впечатляващо CV3. Подготовка на впечатляващо CV
3. Подготовка на впечатляващо CVSvetlin Nakov
 
Софтуерен университет - качествено обучение безплатно (OpenFest 2012)
Софтуерен университет - качествено обучение безплатно (OpenFest 2012)Софтуерен университет - качествено обучение безплатно (OpenFest 2012)
Софтуерен университет - качествено обучение безплатно (OpenFest 2012)Svetlin Nakov
 
Recruitment Advertising 2.0
Recruitment Advertising 2.0Recruitment Advertising 2.0
Recruitment Advertising 2.0Phillip Tusing
 
How to Write a Cover Letter?
How to Write a Cover Letter?How to Write a Cover Letter?
How to Write a Cover Letter?Svetlin Nakov
 
Cloud for Developers: Azure vs. Google App Engine vs. Amazon vs. AppHarbor
Cloud for Developers: Azure vs. Google App Engine vs. Amazon vs. AppHarborCloud for Developers: Azure vs. Google App Engine vs. Amazon vs. AppHarbor
Cloud for Developers: Azure vs. Google App Engine vs. Amazon vs. AppHarborSvetlin Nakov
 

En vedette (15)

Tools for Developers
Tools for DevelopersTools for Developers
Tools for Developers
 
Growing a Developer - Svetlin Nakov @ BHRMDA Conference 2012
Growing a Developer - Svetlin Nakov @ BHRMDA Conference 2012Growing a Developer - Svetlin Nakov @ BHRMDA Conference 2012
Growing a Developer - Svetlin Nakov @ BHRMDA Conference 2012
 
Telerik Software Academy - Info Day - August 2012
Telerik Software Academy - Info Day - August 2012Telerik Software Academy - Info Day - August 2012
Telerik Software Academy - Info Day - August 2012
 
5. Подготовка и явяване на ИТ интервю
5. Подготовка и явяване на ИТ интервю5. Подготовка и явяване на ИТ интервю
5. Подготовка и явяване на ИТ интервю
 
Следвай вдъхновението си!
Следвай вдъхновението си!Следвай вдъхновението си!
Следвай вдъхновението си!
 
1. Търсене на работа в ИТ индустрията: процесът
1. Търсене на работа в ИТ индустрията: процесът1. Търсене на работа в ИТ индустрията: процесът
1. Търсене на работа в ИТ индустрията: процесът
 
Свободно образование и споделяне на знания
Свободно образование и споделяне на знанияСвободно образование и споделяне на знания
Свободно образование и споделяне на знания
 
4. Писане на мотивационно писмо
4. Писане на мотивационно писмо4. Писане на мотивационно писмо
4. Писане на мотивационно писмо
 
Regular Expressions: QA Challenge Accepted Conf (March 2015)
Regular Expressions: QA Challenge Accepted Conf (March 2015)Regular Expressions: QA Challenge Accepted Conf (March 2015)
Regular Expressions: QA Challenge Accepted Conf (March 2015)
 
3. Подготовка на впечатляващо CV
3. Подготовка на впечатляващо CV3. Подготовка на впечатляващо CV
3. Подготовка на впечатляващо CV
 
Софтуерен университет - качествено обучение безплатно (OpenFest 2012)
Софтуерен университет - качествено обучение безплатно (OpenFest 2012)Софтуерен университет - качествено обучение безплатно (OpenFest 2012)
Софтуерен университет - качествено обучение безплатно (OpenFest 2012)
 
Recruitment Advertising 2.0
Recruitment Advertising 2.0Recruitment Advertising 2.0
Recruitment Advertising 2.0
 
How to Write a Cover Letter?
How to Write a Cover Letter?How to Write a Cover Letter?
How to Write a Cover Letter?
 
Job letters ppt
Job letters pptJob letters ppt
Job letters ppt
 
Cloud for Developers: Azure vs. Google App Engine vs. Amazon vs. AppHarbor
Cloud for Developers: Azure vs. Google App Engine vs. Amazon vs. AppHarborCloud for Developers: Azure vs. Google App Engine vs. Amazon vs. AppHarbor
Cloud for Developers: Azure vs. Google App Engine vs. Amazon vs. AppHarbor
 

Similaire à Unit Testing - Nakov's Talk @ VarnaConf 2013 (20)

J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit test
Unit testUnit test
Unit test
 
3 j unit
3 j unit3 j unit
3 j unit
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf
 
Junit 5 - Maior e melhor
Junit 5 - Maior e melhorJunit 5 - Maior e melhor
Junit 5 - Maior e melhor
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptx
 
Security Testing
Security TestingSecurity Testing
Security Testing
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
Junit With Eclipse
Junit With EclipseJunit With Eclipse
Junit With Eclipse
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactus
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
Python unit testing
Python unit testingPython unit testing
Python unit testing
 
Android testing
Android testingAndroid testing
Android testing
 

Plus de Svetlin Nakov

BG-IT-Edu: отворено учебно съдържание за ИТ учители
BG-IT-Edu: отворено учебно съдържание за ИТ учителиBG-IT-Edu: отворено учебно съдържание за ИТ учители
BG-IT-Edu: отворено учебно съдържание за ИТ учителиSvetlin Nakov
 
Programming World in 2024
Programming World in 2024Programming World in 2024
Programming World in 2024Svetlin Nakov
 
AI Tools for Business and Startups
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and StartupsSvetlin Nakov
 
AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Scientists - Nakov (Oct 2023)AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Scientists - Nakov (Oct 2023)Svetlin Nakov
 
AI Tools for Entrepreneurs
AI Tools for EntrepreneursAI Tools for Entrepreneurs
AI Tools for EntrepreneursSvetlin Nakov
 
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023Svetlin Nakov
 
AI Tools for Business and Personal Life
AI Tools for Business and Personal LifeAI Tools for Business and Personal Life
AI Tools for Business and Personal LifeSvetlin Nakov
 
Дипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП - Светлин НаковДипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП - Светлин НаковSvetlin Nakov
 
Дипломна работа: учебно съдържание по ООП
Дипломна работа: учебно съдържание по ООПДипломна работа: учебно съдържание по ООП
Дипломна работа: учебно съдържание по ООПSvetlin Nakov
 
Свободно ИТ учебно съдържание за учители по програмиране и ИТ
Свободно ИТ учебно съдържание за учители по програмиране и ИТСвободно ИТ учебно съдържание за учители по програмиране и ИТ
Свободно ИТ учебно съдържание за учители по програмиране и ИТSvetlin Nakov
 
AI and the Professions of the Future
AI and the Professions of the FutureAI and the Professions of the Future
AI and the Professions of the FutureSvetlin Nakov
 
Programming Languages Trends for 2023
Programming Languages Trends for 2023Programming Languages Trends for 2023
Programming Languages Trends for 2023Svetlin Nakov
 
IT Professions and How to Become a Developer
IT Professions and How to Become a DeveloperIT Professions and How to Become a Developer
IT Professions and How to Become a DeveloperSvetlin Nakov
 
GitHub Actions (Nakov at RuseConf, Sept 2022)
GitHub Actions (Nakov at RuseConf, Sept 2022)GitHub Actions (Nakov at RuseConf, Sept 2022)
GitHub Actions (Nakov at RuseConf, Sept 2022)Svetlin Nakov
 
IT Professions and Their Future
IT Professions and Their FutureIT Professions and Their Future
IT Professions and Their FutureSvetlin Nakov
 
How to Become a QA Engineer and Start a Job
How to Become a QA Engineer and Start a JobHow to Become a QA Engineer and Start a Job
How to Become a QA Engineer and Start a JobSvetlin Nakov
 
Призвание и цели: моята рецепта
Призвание и цели: моята рецептаПризвание и цели: моята рецепта
Призвание и цели: моята рецептаSvetlin Nakov
 
What Mongolian IT Industry Can Learn from Bulgaria?
What Mongolian IT Industry Can Learn from Bulgaria?What Mongolian IT Industry Can Learn from Bulgaria?
What Mongolian IT Industry Can Learn from Bulgaria?Svetlin Nakov
 
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)Svetlin Nakov
 
Blockchain and DeFi Overview (Nakov, Sept 2021)
Blockchain and DeFi Overview (Nakov, Sept 2021)Blockchain and DeFi Overview (Nakov, Sept 2021)
Blockchain and DeFi Overview (Nakov, Sept 2021)Svetlin Nakov
 

Plus de Svetlin Nakov (20)

BG-IT-Edu: отворено учебно съдържание за ИТ учители
BG-IT-Edu: отворено учебно съдържание за ИТ учителиBG-IT-Edu: отворено учебно съдържание за ИТ учители
BG-IT-Edu: отворено учебно съдържание за ИТ учители
 
Programming World in 2024
Programming World in 2024Programming World in 2024
Programming World in 2024
 
AI Tools for Business and Startups
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
 
AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Scientists - Nakov (Oct 2023)AI Tools for Scientists - Nakov (Oct 2023)
AI Tools for Scientists - Nakov (Oct 2023)
 
AI Tools for Entrepreneurs
AI Tools for EntrepreneursAI Tools for Entrepreneurs
AI Tools for Entrepreneurs
 
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
Bulgarian Tech Industry - Nakov at Dev.BG All in One Conference 2023
 
AI Tools for Business and Personal Life
AI Tools for Business and Personal LifeAI Tools for Business and Personal Life
AI Tools for Business and Personal Life
 
Дипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП - Светлин НаковДипломна работа: учебно съдържание по ООП - Светлин Наков
Дипломна работа: учебно съдържание по ООП - Светлин Наков
 
Дипломна работа: учебно съдържание по ООП
Дипломна работа: учебно съдържание по ООПДипломна работа: учебно съдържание по ООП
Дипломна работа: учебно съдържание по ООП
 
Свободно ИТ учебно съдържание за учители по програмиране и ИТ
Свободно ИТ учебно съдържание за учители по програмиране и ИТСвободно ИТ учебно съдържание за учители по програмиране и ИТ
Свободно ИТ учебно съдържание за учители по програмиране и ИТ
 
AI and the Professions of the Future
AI and the Professions of the FutureAI and the Professions of the Future
AI and the Professions of the Future
 
Programming Languages Trends for 2023
Programming Languages Trends for 2023Programming Languages Trends for 2023
Programming Languages Trends for 2023
 
IT Professions and How to Become a Developer
IT Professions and How to Become a DeveloperIT Professions and How to Become a Developer
IT Professions and How to Become a Developer
 
GitHub Actions (Nakov at RuseConf, Sept 2022)
GitHub Actions (Nakov at RuseConf, Sept 2022)GitHub Actions (Nakov at RuseConf, Sept 2022)
GitHub Actions (Nakov at RuseConf, Sept 2022)
 
IT Professions and Their Future
IT Professions and Their FutureIT Professions and Their Future
IT Professions and Their Future
 
How to Become a QA Engineer and Start a Job
How to Become a QA Engineer and Start a JobHow to Become a QA Engineer and Start a Job
How to Become a QA Engineer and Start a Job
 
Призвание и цели: моята рецепта
Призвание и цели: моята рецептаПризвание и цели: моята рецепта
Призвание и цели: моята рецепта
 
What Mongolian IT Industry Can Learn from Bulgaria?
What Mongolian IT Industry Can Learn from Bulgaria?What Mongolian IT Industry Can Learn from Bulgaria?
What Mongolian IT Industry Can Learn from Bulgaria?
 
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
How to Become a Software Developer - Nakov in Mongolia (Oct 2022)
 
Blockchain and DeFi Overview (Nakov, Sept 2021)
Blockchain and DeFi Overview (Nakov, Sept 2021)Blockchain and DeFi Overview (Nakov, Sept 2021)
Blockchain and DeFi Overview (Nakov, Sept 2021)
 

Dernier

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 

Dernier (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 

Unit Testing - Nakov's Talk @ VarnaConf 2013

  • 1. UnitTesting Building Rock-Solid Software Svetlin Nakov Telerik Software Academy http://academy.telerik.com ManagerTechnicalTraining http://www.nakov.com
  • 3. UnitTest – Definition A unit test is a piece of code written by a developer that exercises a very small, specific area of functionality of the code being tested. “Program testing can be used to show the presence of bugs, but never to show their absence!” Edsger Dijkstra, [1972]
  • 4. UnitTest – Example int sum(int[] array) { int sum = 0; for (int i=0; i<array.length; i++) sum += array[i]; return sum; } void testSum() { if (sum(new int[]{1,2}) != 3) throw new TestFailedException("1+2 != 3"); if (sum(new int[]{-2}) != -2) throw new TestFailedException("-2 != -2"); if (sum(new int[]{}) != 0) throw new TestFailedException("0 != 0"); }
  • 5. UnitTesting – Some Facts  Tests are pieces of code (small programs)  In most cases unit tests are written by developers, not by QA engineers  Unit tests are released into the code repository (TFS / SVN / Git) along with the code they test  Unit testing framework is needed  Visual StudioTeamTest (VSTT)  NUnit, MbUnit, Gallio, etc. 5
  • 7. UnitTesting Frameworks  JUnit  The first popular unit testing framework  Based on Java, written by Kent Beck & Co.  Similar frameworks have been developed for a broad range of computer languages  NUnit – for C# and all .NET languages  cppUnit, jsUnit, PhpUnit, PerlUnit, ...  Visual StudioTeamTest (VSTT)  Developed by Microsoft, integrated inVS 7
  • 8. UnitTesting Frameworks  JUnit – the first unit testing framework  www.junit.org  Based on Java  Developed by Erich Gamma and Kent Beck  Unit testing frameworks have been developed for a broad range of computer languages  NUnit – for C#,VB.NET and .NET languages  cppUnit, DUnit, jsUnit, PhpUnit, PerlUnit, ...  List of xUnit frameworks can be found at: http://www.testingfaqs.org/t-unit.html
  • 9. JUnit – Features  Test code is annotated using Java 5 annotations  Test code contains assertions  Tests are grouped in test fixtures and test suites  Several execution interfaces  Eclipse integrated plug-in  Console interface: java org.junit.runner.JUnitCore <test-class>
  • 10. JUnit – Annotations  @Test  Annotates a test case method  @Before, @After  Annotates methods called before/after each test case  @BeforeClass, @AfterClass  Annotates methods called one time before and after all test cases in the class  @Ignore  Ignores a test case 10
  • 11. JUnit – Assertions  Using org.junit.Assert class  Assertions check a condition and throw exception if the condition is not satisfied  Comparing values  assertEquals ([message], expected value, calculated value)  Comparing objects  assertNull([message], object)  assertNotNull([message], object)  assertSame ([message], expected obj, calculated obj)
  • 12. JUnit – Assertions (2)  Conditions  assertTrue(condition)  assertFalse(condition)  Forced test fail  fail()  Expecting exception  @Test(expected=IndexOutOfBoundsExcept ion.class)
  • 13.  Java class that needs unit testing: JUnit – Example public class Sumator { public int sum(int a, int b) { int sum = a + b; return sum; } public int sum(int... nums) { int sum = 0; for (int i = 0; i < nums; i++) sum += nums[i]; return sum; } }
  • 14.  JUnit based test class (fixture): JUnit – Example import org.junit.Test; import static org.junit.Assert.*; public class SumatorTest { @Test public void testSum() { Sumator sumator = new Sumator(); int sum = sumator.sum(new int[] {2,3,4}); assertEquals(sum, 9); } }
  • 15.  JUnit text fixture with setup and cleanup: JUnit – Example public class SumatorTest { private Sumator sumator; @Before public void setUpTestCase() { this.sumator = new Sumator(); } @Test public void testSum() { int sum = sumator.sum(2, 3); assertEquals(sum, 5); } @After public void cleanUpTestCase() { this.sumator = null; } }
  • 16. Test Suites  Suits are sets of JUnit test classes  We can define test suits with annotations: import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(value=Suite.class) @SuiteClasses(value={Test1.class, Test2.class}) public class AllTests { }
  • 17. Eclipse and JUnit  Eclipse has built-in support for integration with JUnit  Can create, run and debug JUnit tests
  • 19. форумпрограмиране,форум уеб дизайн курсовеи уроци по програмиране,уеб дизайн – безплатно програмиранеза деца – безплатни курсове и уроци безплатенSEO курс -оптимизация за търсачки уроципо уеб дизайн, HTML,CSS, JavaScript,Photoshop уроципо програмиранеи уеб дизайн за ученици ASP.NETMVCкурс – HTML,SQL,C#,.NET,ASP.NETMVC безплатенкурс"Разработка на софтуер в cloud среда" BGCoder -онлайн състезателна система -online judge курсовеи уроци по програмиране,книги – безплатно отНаков безплатенкурс"Качествен програменкод" алгоакадемия – състезателно програмиране,състезания ASP.NETкурс -уеб програмиране,бази данни, C#,.NET,ASP.NET курсовеи уроци по програмиране– Телерик академия курсмобилни приложения с iPhone, Android,WP7,PhoneGap freeC#book, безплатна книга C#,книга Java,книга C# Дончо Минков -сайт за програмиране Николай Костов -блог за програмиране C#курс,програмиране,безплатно UnitTesting http://academy.telerik.com
  • 20. FreeTrainings @Telerik Academy  C# Programming @Telerik Academy  csharpfundamentals.telerik.com  Telerik Software Academy  academy.telerik.com  Telerik Academy @ Facebook  facebook.com/TelerikAcademy  Telerik Software Academy Forums  forums.academy.telerik.com