Testing Flashcards
Why is automatic testing better than manual testing?
- takes less time
- can be run again and again
- useful for big projects with multiple developers working on them
What are the types of tests that exist?
- unit
- integration
- system
- acceptance
For what part is unit testing done?
Tests specific code sections; each test is for a specific unit of code(small)
Detailed Design
For what is integration testing done?
It tests whether the components work properly together; for complex integration with external services
Architectural Design
What is system testing used for?
It tests complete, real program flows
What is acceptance testing used for?
It tests whether the program fulfils the requirements; usually done with/by the customer
Requirements definition
What is the reglementation used for a coding project and what does it mean?
SPICE - Software Process Improvement and Capability dEtermination(top-down design and bottom-up testing)
What does top-down design mean?
- Requirements
- Architectural Design
- Detailed design
- Coding
- Configuration
What does bottom-up testing mean?
- Configuration
- Testing Data Preparation
- Unit
- Integration
- Acceptance
What are the stages of TDD?
- Design
- Writing Tests
- Writing code
- Refactoring
What is TDD?
Test Driven Development; the concept of defining a method’s specifications through assertions in a test before implementing the method itself.
Why choose TDD?
- tests take time
- they are boring
- less testing if they are left right before the deadline
Should the stages of TDD be done by the same person/team?
No, most stages should be carried out by separate teams so that the people writing the tests would have no knowledge of the implementation. This way, they can test everything from the perspective of the client and be more thorough.
What is JUnit?
A testing framework that can be used for automatic unit testing. The test files are simple classes that make use of annotations and assertions to perform the tests.
What are annotations?
They are structures added above a method to augment its behavior. (@Test, @BeforeEach, @AfterAll etc)
What are assertions?
Statements that verify certain characteristics of the code(for boolean true or false, if an object is null or not, if two values are equal or not, if two objects are the same or not etc)
When using assertSame or assertEquals what represent the first and second values?
First value is the expected one and the second is the actual one.
What are some good practices of testing?
- aim for one assert per test(enforce every test to test a different case)
- unit tests should be indepenedent
- tests should not interfere with one another
- passing tests should not be producing any output, but failing ones should
- when you find a bug not included in the tests, try to test it, because it might not be the cause you believe it to be
What to test?
- public/protected instances
- constructor
- getters and setters only if the have additional logic
- test also what a method should not do
- edge cases
What happens when two methods depend on each other from the testing point of view?
This is called circular dependency and it should be prevented as much as possible. In cases where this cannot be done, the methods should be tested in a single test method.
What does refactoring mean?
Refactoring code means making changes
in the code that improve readability, structure, efficiency, flexibility and maintainability without changing the functionality.
What are some advantages of refactoring?
- Code will become more readable.
- Code will become more efficient.
- Code will become easier maintainable.
- Code will become more flexible.
What are code smells?
Code smells are generally the result of bad coding practices.
what are some examples of code smells?
- Code duplication
- Contrived complexity
- Long methods
- Data clumps
- Many methods needed from another class
- Code in comments
- Comments in methods
- Long list of parameters
- Switch construction for type checking
- Large classes
- Un-encapsulated fields
- Undescriptive naming
- Inconsistent naming
- Dead code
- Middle man
- Solution sprawl
How should you refactor code?
- Make a small change in your code (a single refactoring)
- Run all tests to ensure everything still works
- If so, move to the next refactoring
- If the tests do not pass, fix the newly created problem (or simply undo the change if the former is impossible).