Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.
-
Upload
felicity-melton -
Category
Documents
-
view
232 -
download
0
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.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/1.jpg)
Unit TestingContinuous IntegrationPYUNIT AND JENKINS FRAMEWORK
PresenterRachita Agasthy
![Page 2: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/2.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/3.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/4.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/5.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/6.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/7.jpg)
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.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/8.jpg)
Homepage
![Page 9: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/9.jpg)
Creating new Job
![Page 10: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/10.jpg)
Enter Job Details
![Page 11: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/11.jpg)
Advanced Job Options
![Page 12: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/12.jpg)
When to run the job?
![Page 13: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/13.jpg)
What happens when job runs?
![Page 14: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/14.jpg)
Other features
◦ Managing Jenkins
![Page 15: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/15.jpg)
More managing options
![Page 16: Unit Testing Continuous Integration PYUNIT AND JENKINS FRAMEWORK Presenter Rachita Agasthy.](https://reader035.fdocuments.in/reader035/viewer/2022062321/56649e865503460f94b8938a/html5/thumbnails/16.jpg)
Thank you!