Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Case Study: Testing Overview You are required to test three shape classes using the Pytest framework. One test suite is required for each class. You
Case Study: Testing
Overview
You are required to test three shape classes using the Pytest framework. One test suite is required for each class. You will test the methods of each class using unit tests. Your tests must ensure the code functions as intended and the expected output is received. Finally, you are required to setup two fixtures per test suite.
Rectangle Test Suite
Create a testing class which tests the functionality of a rectangle.
Implement a minimum of two fixtures which instantiate and return a Rectangle.
Create methods to test the calculatearea, calculateperimeter, and scale methods.
A minimum of two asserts should be written for each unit test.
Testing the scale of a rectangle requires you to invoke scale from each fixture, then check the rectangles attributes: length and width. You should check the area after to ensure it remains correct post scale.
Circle Test Suite
Create a testing class which tests the functionality of a circle.
Implement a minimum of two fixtures which instantiate and return a Circle.
Create methods to test the calculatearea, calculateperimeter, and scale methods.
A minimum of two asserts should be written for each unit test.
Testing the scale of a circle requires you to invoke scale from each fixture, then check the circle attributes: radius. You should check the area after to ensure it remains correct post scale.
Triangle Test Suite
Create a testing class which tests the functionality of a triangle.
Implement a minimum of two fixtures which instantiate and return a Triangle.
Create methods to test the calculatearea, calculateperimeter, and scale methods.
A minimum of two asserts should be written for each unit test.
Testing the scale of a triangle requires you to invoke scale from each fixture, then check the triangles attributes: hypotenuse, opposite, and adjacent. You should check the area after to ensure it remains correct post scale.
The Triangle class has a calculatesemiperimeter method which should also be tested.
Challenge
While testing your triangle, you may find you receive a math domain error.
Explore this issue and identify why this may occur.
Discuss this with your pair programming partner
Implement code to fix the affected class.
a Only allow objects of that class be instantiated correctly.
Note: Please only attempt the challenge once your workshop tasks are completed and verified with your supervisor.
Hints
Three separate testing suites are required and therefore, three separate modules and testing classes.
Only import the shape you need to test. ie do not write a wildcard import.
Test suite modules begin with test
Test classes begin with Test
Testing methods begin with test
Testing the scale of each shape requires you to firstly invoke scale from each fixture, then check their associated attributes which were changed.
As a precaution, you should check the area after to make sure this was calculated post scale.
Tests can simply test the expected output of each function.
You are required to implement unit tests which test a unit of code. method in this case
Output
Run your pytests for each test suite by opening the terminal and entering pytest
Case Study: Testing
Overview
You are required to test three shape classes using the Pytest framework. One test suite is required for each class. You will test the methods of each class using unit tests. Your tests must ensure the code functions as intended and the expected output is received. Finally, you are required to setup two fixtures per test suite.
Rectangle Test Suite
Create a testing class which tests the functionality of a rectangle.
Implement a minimum of two fixtures which instantiate and return a Rectangle.
Create methods to test the calculatearea, calculateperimeter, and scale methods.
A minimum of two asserts should be written for each unit test.
Testing the scale of a rectangle requires you to invoke scale from each fixture, then check the rectangles attributes: length and width. You should check the area after to ensure it remains correct post scale.
Circle Test Suite
Create a testing class which tests the functionality of a circle.
Implement a minimum of two fixtures which instantiate and return a Circle.
Create methods to test the calculatearea, calculateperimeter, and scale methods.
A minimum of two asserts should be written for each unit test.
Testing the scale of a circle requires you to invoke scale from each fixture, then check the circle attributes: radius. You should check the area after to ensure it remains correct post scale.
Triangle Test Suite
Create a testing class which tests the functionality of a triangle.
Implement a minimum of two fixtures which instantiate and return a Triangle.
Create methods to test the calculatearea, calculateperimeter, and scale methods.
A minimum of two asserts should be written for each unit test.
Testing the scale of a triangle requires you to invok
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started