How to use the Random Module in Python
We want the computer to pick a random number in a given range Pick a random element from a list,
pick a random card from a deck, flip a coin etc. When making your password database more secure or
powering a random page feature of your website.
- Randint(): random.randint(0, 5) range 0 to 5.
- Random(): random.random() * 100 range 0 to 100.
- Choice(): Generate a random value from the sequence sequence.
- Shuffle(): shuffles the elements in list in place, so they are in a random order.
- Randrange(): Generate a randomly selected element from range(start, stop, step).
Risk Analysis in Software Testing
risk analysis is the process of identifying the risks in applications or software that
you built and prioritizing them to test. After that, the process of assigning the level of risk
is done. The categorization of the risks takes place, hence, the impact of the risk is calculated.
- Why use Risk Analysis?
helps the developers and managers to mitigate the risks. When a test plan has been created, risks involved in testing the product are to be taken into consideration along with the possibility of the damage they may cause to your software along with solutions.
- Possible risks
Use of new hardware
Use of new technology
Use of new automation tool
The sequence of code
Availability of test resources for the application
- Risk identification
Business Risks: This risk is the most common risk associated with our topic. It is the risk that may come from your company or your customer, not from your project.
Testing Risks: You should be well acquainted with the platform you are working on, along with the software testing tools being used.
Premature Release Risk: a fair amount of knowledge to analyze the risk associated with releasing unsatisfactory or untested software is required
Software Risks: You should be well versed with the risks associated with the software development process.
- Perform risk Assessment
Searching the risk
Analyzing the impact of each individual risk
Measures for the risk identified
Test Coverage
Test coverage is a useful tool for finding untested parts of a codebase.
Test coverage is of little use as a numeric statement of how good your tests are.
- TDD is a very useful, but certainly not sufficient, tool to help you get good tests.
- a coverage percentage in the upper 80s or 90s
- One sign you are testing too much is if your tests are slowing you down.
Dependency Injection
dependency injection is a technique whereby one object (or static method) supplies the dependencies of another object.
A dependency is an object that can be used (a service).
When class A uses some functionality of class B, then its said that class A has a dependency of class B.
- Three types of dependency injection:
1, constructor injection: the dependencies are provided through a class constructor.
2, setter injection: the client exposes a setter method that the injector uses to inject the dependency.
3, interface injection: the dependency provides an injector method that will inject the dependency into
any client passed to it. Clients must implement an interface that exposes a setter method that accepts the dependency.
- Benefits and Disadvantages of DI
Help unit testing
Extending the application and enable loose coupling
Complex to learn
Compile errors