Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

16
Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy

Transcript of Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Page 1: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Unit TestingContinuous IntegrationPYUNIT AND JENKINS FRAMEWORK

PresenterRachita Agasthy

Page 2: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Unit Testing Goal – Isolate parts of the code, test their individual working.

Why do Unit testing?

Unit testing is a part of most of software development methodologies in use today• Agile Methodologies• Extreme Programming• Test Driven Development

Page 3: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Advantages and Disadvantages Advantages

Reduction in flaws – Statistics suggest 90% reduction in bugs during QA process

Repeatability – Can reuse the same tests as and when you make changes

Disadvantages

Requires approximately 30% more time at the start of the project

Written by developer, not possible to cover all the cases

Frameworks Available – GUnit(C++), JUnit(Java), PyUnit(Python), test-unit(Ruby) and so on.

Page 4: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Unit testing example - PyUnit

class Calculator(object):

def add(self, value1, value2):

return value1 + value2

Actual Code: Test Code:

class CalculatorUnitTest(unittest.TestCase):def setup(self):

// Code that is common to every// test in this class.myCalculator = Calculator()

def test_add(self):// Positive value additionresult = myCalculator.add(100,

20)errMsg = “Expected 120 but got

”+ resultassert result == 120, errMsg// Negative value additionresult = myCalculator.add(-10,

-20)errMsg = “Expected -30 but got

”+ resultassert result == -30, errMsg

if __name__ == "__main__":unittest.main()

Page 5: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Mocking in Unit Tests

class Calculator(object):

def add(self, value1, value2):

return value1 + value2

def multiply(self, value1, value2):

result_arr = []

for i in xrange(0,value2/2)

result.append(add(value1, value1)

if value2 % 2 != 0:

result = value1

for value in result_arr:

result = result + value1;

return result

Actual Code: Test Code:

class CalculatorUnitTest(unittest.TestCase):def setup(self):

// Code that is common to every// test in this class.myCalculator = Calculator()

def test_multiply(self):val1 = 10val2 = 20// Positive value multiplicationmyCalculator.add =

MagicMock(return_value = 20)result = myCalculator.multiply(val1,

val2)errMsg = “Expected 200 but got ”+

resultassert result == 200, errMsg

if __name__ == "__main__":unittest.main()

Page 6: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Continuous Integration Development work is integrated at a predefined time or event

Resulting work is automatically tested and built

Advantage◦ Automated Unit Testing ◦ Development errors are identified very early in the process◦ Continuous Quality Control

Usage: Extensively used in Extreme Programming

Frameworks Available – CruiseControl, Jenkins, Buildbot and so on.

Page 7: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Jenkins Open source Java based tool.

Basic functionality◦ Detect code changes in the code repository◦ Build different parts of the code◦ Run unit tests◦ Run the different components of the system◦ Verify the output◦ In case of failures, notify the developer who caused the failure.◦ Also notify other developers

Requirements◦ Requires installation on the server◦ Accessible through a web page

Page 8: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Homepage

Page 9: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Creating new Job

Page 10: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Enter Job Details

Page 11: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Advanced Job Options

Page 12: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

When to run the job?

Page 13: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

What happens when job runs?

Page 14: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Other features

◦ Managing Jenkins

Page 15: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

More managing options

Page 16: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.

Thank you!