Download presentation
Presentation is loading. Please wait.
Published byFelicity Melton Modified over 9 years ago
1
Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy
2
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
3
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.
4
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 addition result = myCalculator.add(100, 20) errMsg = “Expected 120 but got ”+ result assert result == 120, errMsg // Negative value addition result = myCalculator.add(-10, -20) errMsg = “Expected -30 but got ”+ result assert result == -30, errMsg if __name__ == "__main__": unittest.main()
5
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 = 10 val2 = 20 // Positive value multiplication myCalculator.add = MagicMock(return_value = 20) result = myCalculator.multiply(val1, val2) errMsg = “Expected 200 but got ”+ result assert result == 200, errMsg if __name__ == "__main__": unittest.main()
6
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.
7
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
8
Homepage
9
Creating new Job
10
Enter Job Details
11
Advanced Job Options
12
When to run the job?
13
What happens when job runs?
14
Other features ◦Managing Jenkins
15
More managing options
16
Thank you!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.