Programming in Visual Basic

Chapter 11
Quality Engineering, Testing, Security, and Ethics

Post Graduate Program in Computer Science Engineering
Programming in Visual Basic   •   Post Graduate

Quality Engineering, Testing, Security, and Ethics

Introduction

Visual Basic, particularly Visual Basic .NET (VB.NET), is used to develop desktop, web, service-oriented, database, and enterprise applications. Although the language provides type safety, exception handling, structured libraries, and an extensive development environment, these facilities do not automatically produce reliable or ethical software. Quality depends on deliberate engineering practices applied throughout the software life cycle.

Quality engineering integrates prevention, measurement, verification, validation, operational feedback, security, and ethical judgement. Testing is one part of this discipline. A program may pass its functional tests and still be insecure, inaccessible, slow, difficult to maintain, or harmful to users. This chapter therefore treats quality as a socio-technical property of the complete VB.NET system rather than as the absence of compiler errors.

Learning Objectives

After studying this chapter, the reader should be able to:

  1. Explain software quality dimensions and quality-engineering principles.
  2. Design effective test strategies for VB.NET applications.
  3. Apply unit, integration, system, acceptance, regression, performance, and security testing.
  4. Use VB.NET features such as interfaces, dependency injection, assertions, and exception handling to improve testability.
  5. Interpret coverage and defect metrics without misusing them.
  6. Identify common application vulnerabilities and propose controls.
  7. Evaluate ethical, privacy, accessibility, and governance implications of software decisions.
  8. Construct a quality plan for a realistic VB.NET application.

1. Software Quality as an Engineering Property

A useful distinction is between quality assurance (QA), quality control (QC), and quality engineering. QA establishes and improves the processes used to create software. QC evaluates products and identifies nonconformities. Quality engineering combines process design, technical prevention, automated feedback, measurement, and risk management so that defects are prevented or detected as early and cheaply as possible.

Quality is multidimensional. ISO/IEC 25010 provides a useful conceptual basis, although organizations may adapt it to their context. Important characteristics include:

Quality characteristicMeaning in a VB.NET systemTypical evidence
Functional suitabilityRequired functions are correct and completeAcceptance tests, domain tests
Performance efficiencyResponse time and resource use are appropriateLoad and profiling results
CompatibilityComponents coexist and exchange data correctlyIntegration tests
Usability and accessibilityUsers can understand and operate the systemUsability sessions, keyboard testing
ReliabilityThe system performs consistently and recovers appropriatelyFailure and recovery tests
SecurityConfidentiality, integrity, authentication, and availability are protectedThreat models, security tests
MaintainabilitySoftware can be changed safely and economicallyCode review, design metrics
PortabilitySoftware can operate across intended environmentsDeployment tests

Quality attributes often conflict. Strong encryption may add processing overhead; extensive logging may assist diagnosis but expose personal data; a highly abstract design may improve extensibility while increasing learning cost. Consequently, quality requirements should be explicit, measurable, prioritized, and linked to business and user risks.

Verification and Validation

Verification asks, “Are we building the product right?” It includes reviews, static analysis, compilation, unit testing, and conformance checks. Validation asks, “Are we building the right product?” It includes user evaluation, acceptance testing, operational pilots, and examination of whether the system solves the intended problem.

Testing cannot prove that a non-trivial program is completely correct. It provides evidence under selected conditions. The strength of that evidence depends on requirements, test design, data quality, independence, environment realism, and the adequacy of the oracle used to decide whether an output is correct.

2. Quality Engineering Across the Life Cycle

A mature process shifts quality activities leftward, while also retaining production feedback. Requirements should identify measurable quality objectives, such as “95% of authenticated requests complete within 500 ms under the defined workload.” Architecture should address security boundaries, failure handling, observability, deployment, and recovery. Implementation should use coding standards, reviews, static analysis, automated tests, and secure libraries. Release should require evidence-based quality gates rather than subjective confidence.

The plan–do–check–act cycle is applicable to software quality:

  • Plan: identify stakeholders, risks, requirements, test strategy, and acceptance criteria.
  • Do: implement incrementally using controlled practices.
  • Check: inspect artifacts, execute tests, analyze metrics, and examine incidents.
  • Act: correct defects, improve process, revise standards, and update risks.

A risk-based approach prioritizes effort according to potential harm and uncertainty. A simple qualitative risk model is:

Risk exposure = Probability of failure × Impact of failure

Probability and impact may be ordinal ratings rather than precise probabilities. The expression is therefore a prioritization aid, not a scientifically exact forecast. For example, a payment calculation with moderate likelihood of failure but catastrophic financial impact may receive greater testing priority than a cosmetic display defect with high likelihood but negligible impact.

3. Designing a Test Strategy for VB.NET

A test strategy specifies what will be tested, at which level, with which techniques, data, environments, tools, responsibilities, and exit criteria. It should trace tests to requirements and risks.

Test Levels

  1. Unit testing examines a small unit such as a function, class, or module in isolation. Dependencies are replaced with test doubles where appropriate.
  2. Integration testing examines interactions among components, databases, files, APIs, or messaging systems.
  3. System testing evaluates the complete application against functional and non-functional requirements.
  4. Acceptance testing determines whether stakeholders can accept the system for operational use.
  5. Regression testing repeats selected tests after change to detect unintended effects.
  6. Operational and recovery testing evaluates installation, backup, restoration, monitoring, failover, and graceful degradation.

A “test pyramid” is a useful heuristic: many fast unit tests, fewer integration tests, and a smaller number of broad end-to-end tests. It is not a law. Systems with complex integration boundaries may require a substantial integration suite, while a graphical application may need specialized UI tests.

Test Design Techniques

Equivalence partitioning divides inputs into classes expected to behave similarly. For an age field accepting integers from 18 through 65, representative classes include below 18, 18–65, above 65, non-numeric input, and blank input.

Boundary-value analysis tests edges because faults frequently occur at transitions: 17, 18, 65, and 66 in the preceding example. It should also consider representation limits, such as empty strings, maximum lengths, decimal precision, and date-time boundaries.

Decision-table testing represents combinations of conditions and actions. It is particularly useful for authorization rules, discounts, eligibility, and validation policies.

State-transition testing models states and events. An account may move from Pending to Active, Suspended, or Closed. Tests should include valid transitions, invalid transitions, repeated events, and recovery after failure.

Property-based testing checks general properties over many generated inputs. For a sorting function, a property may be that the output is ordered and is a permutation of the input. This is valuable when individual examples cannot cover a large input space.

Mutation testing deliberately introduces small code changes, called mutants, and measures whether tests detect them. A surviving mutant indicates a possible weakness in the test suite. Mutation scores should be interpreted alongside risk and code structure, not treated as an absolute quality grade.

The Test Oracle Problem

A test oracle determines the expected result. For simple calculations, the oracle may be a trusted formula. For recommendations, optimization, or machine-learning outputs, exact expected values may not exist. Metamorphic relations can help: changing an irrelevant input should not change the result, or processing records in a permitted order should yield an equivalent aggregate. Oracle design is often more difficult than test execution.

4. Testability in Visual Basic

Testability is a design property. Code that isolates responsibilities and controls dependencies is easier to test than code that combines user-interface events, database access, business rules, and file operations in one procedure.

Consider a domain service separated from the user interface:

Public Interface IExchangeRateProvider
    Function GetRate(currencyCode As String) As Decimal
End Interface

Public Class PriceService
    Private ReadOnly rates As IExchangeRateProvider

    Public Sub New(rateProvider As IExchangeRateProvider)
        rates = rateProvider
    End Sub

    Public Function Convert(amount As Decimal, currencyCode As String) As Decimal
        If amount < 0D Then Throw New ArgumentOutOfRangeException(NameOf(amount))
        Dim rate = rates.GetRate(currencyCode)
        If rate <= 0D Then Throw New InvalidOperationException("Invalid exchange rate")
        Return amount * rate
    End Function
End Class

The service depends on an interface rather than a concrete network client. A unit test can provide a deterministic fake provider. This is an example of dependency inversion and constructor injection. In real financial systems, rounding rules, currency precision, rate timestamps, and rate provenance must also be specified; a test that verifies only multiplication is insufficient.

A test framework such as MSTest, NUnit, or xUnit can execute assertions. The exact attributes differ by framework, but a useful unit test should have a clear Arrange–Act–Assert structure:

<TestMethod>
Public Sub Convert_UsesProvidedRate()
    Dim fake = New FixedRateProvider(1.2D)
    Dim service = New PriceService(fake)

    Dim result = service.Convert(10D, "EUR")

    Assert.AreEqual(12D, result)
End Sub

Tests should be deterministic, isolated, repeatable, and fast where possible. Time, randomness, environment variables, network access, file paths, and shared mutable state should be abstracted or controlled. Tests must also verify failures and invalid inputs, not only successful paths.

Exception Handling and Observability

Exceptions should represent abnormal conditions that the current layer cannot reasonably handle. They should not be used for ordinary branching. Catch specific exceptions, preserve diagnostic context, and avoid exposing stack traces or secrets to end users. Logging should support correlation and diagnosis while minimizing personal and confidential data.

A robust application distinguishes:

  • user-correctable validation errors;
  • transient failures that may be retried safely;
  • authorization failures that should be denied and recorded;
  • programming defects requiring correction; and
  • catastrophic conditions requiring controlled shutdown or escalation.

Retries must be bounded and used only when the operation is idempotent or protected against duplication. Exponential backoff and a circuit breaker may reduce pressure on failing services, but they do not replace root-cause analysis.

5. Metrics and Quality Evidence

Metrics guide decisions but can distort behavior when used as targets without context. Common measures include:

  • Defect density: defects divided by a defined size measure, such as thousand lines of code. Size definitions must be consistent, and comparisons across languages can be misleading.
  • Test pass rate: passed tests divided by executed tests. A high rate is meaningless if tests are weak or redundant.
  • Code coverage: the proportion of executed statements, branches, or conditions. Coverage indicates exercised code, not correctness.
  • Defect removal efficiency:
DRE = Defects removed before release ÷ (Defects removed before release + Defects found after release) × 100%

This measure assumes defects are consistently classified and that post-release discovery is observed over a meaningful period. A high DRE may indicate effective prevention, but it may also reflect under-reporting or a very limited operational population.

  • Mean time to restore (MTTR): average time required to restore service after failure. The population, start point, and end point must be defined.
  • Change failure rate: proportion of deployments causing rollback, incident, or urgent remediation. It is useful for delivery improvement when incident classification is consistent.

Quality dashboards should combine leading indicators—reviews, static-analysis findings, risk closure, and test design—with lagging indicators such as incidents and escaped defects. Metrics should trigger investigation, not punishment.

6. Application Security in VB.NET

Security is a quality attribute and a continuous risk-management activity. A practical threat-modeling process identifies assets, actors, trust boundaries, entry points, threats, mitigations, and residual risk. STRIDE is one possible model: spoofing, tampering, repudiation, information disclosure, denial of service, and elevation of privilege.

Core Security Controls

Input validation and output encoding. Treat all external data as untrusted. Validate type, length, range, format, and business meaning at the server or trusted boundary. Use parameterized database commands rather than string concatenation:

Using command As New SqlCommand(
    "SELECT Id, Name FROM Users WHERE Email = @email", connection)
    command.Parameters.Add("@email", SqlDbType.NVarChar, 254).Value = email
    ' Execute command safely.
End Using

Parameterized queries reduce SQL-injection risk, but they do not validate authorization or business rules. HTML, URL, XML, and command contexts require context-appropriate encoding; a single universal escaping function is unsafe.

Authentication and authorization. Authentication establishes identity; authorization determines permitted actions. Enforce least privilege, deny by default, separate administrative roles, and perform authorization checks on the server. Do not rely on hidden controls or client-side restrictions.

Secrets and cryptography. Passwords should be processed with a modern, salted, adaptive password-hashing scheme through a maintained library; they should not be encrypted for later retrieval or stored as plain text. API keys and connection strings should not be committed to source code. Use a managed secret store and rotate credentials. Cryptography should use established algorithms, secure random generation, authenticated encryption where appropriate, and certificate validation. Designing cryptographic primitives independently is rarely justified.

Data protection. Classify data, minimize collection, limit retention, restrict access, encrypt data in transit and at rest where justified, and securely dispose of unnecessary copies. Backups require access control and restoration testing.

Memory, files, and serialization. Validate file names and paths to prevent traversal, constrain upload size and type, store uploads outside executable directories, and avoid unsafe deserialization of untrusted objects. XML processing must be configured to prevent dangerous external entity behavior where applicable.

Dependency and supply-chain security. Maintain an inventory of packages, monitor vulnerabilities, pin or constrain versions appropriately, verify package sources, review licenses, and scan build artifacts. A vulnerable dependency may compromise an otherwise well-tested application.

Secure development lifecycle. Security requirements, threat modeling, code review, static analysis, dependency scanning, dynamic testing, penetration testing, incident response, and patch management should be integrated into delivery. Security testing must be authorized and conducted in controlled environments.

7. Ethics, Privacy, and Professional Responsibility

Software engineers have duties beyond satisfying a customer contract. They should protect users from foreseeable harm, communicate limitations honestly, respect privacy, preserve confidentiality, and avoid discriminatory or deceptive behavior. Professional codes such as those associated with ACM and IEEE provide principles, but ethical judgement remains contextual.

Important issues include:

  • Informed consent: users should understand meaningful collection and use of their data.
  • Purpose limitation: data collected for one purpose should not silently be repurposed.
  • Fairness: automated decisions should be evaluated for disparate effects and unjustified proxies.
  • Accessibility: systems should support users with disabilities through keyboard operation, screen-reader compatibility, clear errors, sufficient contrast, and accessible alternatives.
  • Transparency: consequential decisions should be explainable to an appropriate degree, with avenues for correction and appeal.
  • Responsible disclosure: vulnerabilities should be reported to affected parties with enough information to enable remediation while reducing unnecessary exposure.
  • Whistleblowing and escalation: engineers may need to escalate serious safety, security, privacy, or legal risks when ordinary channels fail.

Privacy regulations vary by jurisdiction. A quality plan should identify applicable obligations, data-controller or processor responsibilities, retention rules, breach procedures, cross-border transfers, and rights of data subjects. Compliance is a baseline, not proof of ethical adequacy.

AI-Assisted Development

AI coding assistants can generate VB.NET code, tests, and documentation, but generated output may contain insecure APIs, licensing conflicts, hallucinated behavior, bias, or hidden data leakage. Organizations should define what code and data may be submitted to external services, require human review, test generated code adversarially, preserve provenance where required, and prohibit the assistant from becoming the sole decision-maker for safety- or rights-critical functions.

8. Illustrative Case: Secure Student Assessment Portal

Background. A university develops a VB.NET portal through which students submit assignments, instructors grade them, and administrators produce reports. The system stores identities, submissions, grades, feedback, and audit records.

Problem. An initial prototype performs functional demonstrations but has weak access controls, concatenated SQL queries, inconsistent validation, and no tested recovery procedure. A student reports that changing an identifier in a URL displays another student’s submission.

Analysis. The incident indicates broken object-level authorization, not merely a user-interface defect. Assets include grades, personal data, intellectual property, and audit integrity. Threat modeling identifies unauthorized access, grade tampering, disclosure through logs, denial of service from large uploads, and loss of data after database failure.

Approach. The team establishes requirements: students may access only their own submissions; instructors may access assigned courses; administrators receive audited privileged access. Repository methods accept the authenticated principal and enforce authorization at the service boundary. SQL commands are parameterized. Uploads are size-limited, type-checked, renamed using server-generated identifiers, and stored outside the web root. Tests cover valid and invalid state transitions, boundary file sizes, repeated submissions, concurrent grading, and unauthorized identifier substitution.

Security and quality gates include static analysis, dependency review, dynamic testing in a non-production environment, backup restoration, accessibility checks, and a privacy review. Audit logs record relevant administrative actions but omit unnecessary submission contents and credentials. A deployment runbook defines rollback, incident notification, and evidence preservation.

Outcome. The redesigned service blocks cross-student access, produces repeatable test evidence, and restores a simulated database backup within the defined recovery objective. The team also discovers that an apparently harmless debug log exposed student email addresses, demonstrating that security and privacy must be considered together.

Learning points. Authorization must be enforced where the protected operation occurs; secure coding controls must be combined with tests; operational recovery is part of quality; and ethical design includes data minimization, accessibility, and transparent governance.

9. Challenges and Limitations

Complete testing is usually infeasible because input combinations, execution environments, timing effects, and integrations are too numerous. Automated tests may encode incorrect assumptions, become brittle, or create false confidence. UI automation can be slow and fragile. Static analysis produces false positives and may miss logic flaws. Penetration testing is time-bounded and cannot establish the absence of vulnerabilities. Metrics can be gamed, and ethical risks may emerge only after deployment.

The response is not to abandon measurement but to triangulate evidence. Combine reviews, automated tests, exploratory testing, production monitoring, user research, threat modeling, incident learning, and independent challenge. Reassess risks when requirements, dependencies, regulations, architecture, or threat conditions change.

10. Best-Practice Checklist

A professional VB.NET quality plan should:

  1. Trace requirements to risks, tests, and acceptance evidence.
  2. Separate presentation, application, domain, and infrastructure responsibilities.
  3. Inject external dependencies and control time, randomness, and environment in tests.
  4. Test normal, boundary, invalid, exceptional, concurrent, and recovery behavior.
  5. Use parameterized queries, least privilege, secure secret storage, and maintained cryptographic libraries.
  6. Treat authorization as a server-side business rule.
  7. Integrate static analysis, dependency scanning, code review, and security testing into delivery.
  8. Measure coverage and defects with explicit definitions and avoid simplistic targets.
  9. Protect privacy, accessibility, auditability, and user autonomy.
  10. Monitor production behavior and feed incidents into engineering improvement.

Chapter Summary

Quality engineering in VB.NET is a life-cycle discipline involving prevention, verification, validation, measurement, security, operational readiness, and ethical responsibility. Quality attributes include functional suitability, performance, reliability, usability, accessibility, maintainability, portability, and security. Effective testing uses multiple levels and techniques, including unit, integration, system, acceptance, regression, boundary, decision-table, state-transition, property-based, and mutation testing.

Testable architecture separates responsibilities and injects dependencies. Metrics such as coverage, defect removal efficiency, and change failure rate provide evidence only when their definitions and limitations are understood. Secure VB.NET development requires validated inputs, parameterized queries, strong authentication and authorization, protected secrets, safe file and serialization practices, dependency governance, and continuous threat assessment. Ethical practice adds privacy, fairness, accessibility, transparency, responsible disclosure, and human accountability. The central principle is that reliable software is engineered through interacting technical, organizational, and human controls rather than demonstrated by a single test result.

Key Terms

Quality engineering: Integrated discipline for preventing, measuring, and improving software quality.

Quality assurance: Process-oriented activities intended to create confidence in development practices.

Quality control: Product evaluation to identify defects or nonconformities.

Verification: Evaluation of whether software conforms to specified requirements.

Validation: Evaluation of whether software meets real user and stakeholder needs.

Test oracle: Mechanism or rule used to determine whether an observed result is correct.

Unit testing: Testing an isolated software unit.

Integration testing: Testing interactions among components or external systems.

Regression testing: Re-execution of tests after change.

Equivalence partitioning: Dividing inputs into classes expected to behave similarly.

Boundary-value analysis: Testing values at and near input or state boundaries.

Mutation testing: Evaluating tests by checking whether they detect deliberately introduced code faults.

Dependency injection: Supplying a component’s dependencies from outside the component.

Threat modeling: Structured identification and treatment of assets, threats, and controls.

Authentication: Establishing the identity of a user or system.

Authorization: Determining what an authenticated actor may do.

Least privilege: Granting only the permissions necessary for an authorized task.

Data minimization: Collecting and retaining only data necessary for a specified purpose.

Defect removal efficiency: Percentage of identified defects removed before release relative to all identified defects.

Technical debt: Future cost created by expedient technical decisions or deferred corrective work.

Review Questions

Short Answer Questions

  1. Distinguish verification from validation.
  2. Why does high code coverage not prove software correctness?
  3. What is the purpose of dependency injection in VB.NET testing?
  4. Explain the difference between authentication and authorization.
  5. State two ethical obligations relevant to student-data software.

Long Answer Questions

  1. Explain how a risk-based quality strategy can be developed for an enterprise VB.NET application.
  2. Compare unit, integration, system, acceptance, and regression testing, including suitable examples.
  3. Discuss how input validation, parameterized queries, authorization, and secret management reduce application risk.
  4. Critically evaluate software quality metrics and explain how organizations can avoid metric-driven dysfunction.
  5. Describe an ethical and privacy-aware life-cycle for developing a system that makes consequential decisions.

Analytical / Application Questions

  1. Design equivalence partitions and boundary tests for a VB.NET function that accepts a non-negative decimal amount between 0.01 and 9,999.99.
  2. A portal passes all functional tests but permits a student to view another student’s record by changing an identifier in a URL. Diagnose the vulnerability and propose architectural, coding, and testing controls.
  3. Construct a compact quality and security plan for a VB.NET medical appointment system. Identify at least five risks, corresponding tests or controls, and the ethical implications of each.

Multiple Choice Questions with Answers

Question 1

Which statement best distinguishes verification from validation?

A. Verification checks whether requirements are implemented correctly; validation checks whether the right product was built.

B. Verification is performed only after deployment; validation is performed only during coding.

C. Verification concerns security only; validation concerns performance only.

D. Verification is manual testing; validation is automated testing.

Correct Answer: A. Verification checks whether requirements are implemented correctly; validation checks whether the right product was built.

Question 2

Which design most directly improves unit-test isolation in VB.NET?

A. Embedding database calls inside every user-interface event handler

B. Using constructor injection with an interface for an external dependency

C. Replacing all exceptions with global variables

D. Storing configuration in hard-coded string literals

Correct Answer: B. Using constructor injection with an interface for an external dependency

Question 3

What is the principal security benefit of a parameterized SQL command?

A. It guarantees that the user is authorized to read every returned row.

B. It prevents all denial-of-service attacks.

C. It separates SQL structure from supplied parameter data, reducing SQL injection risk.

D. It encrypts the database automatically.

Correct Answer: C. It separates SQL structure from supplied parameter data, reducing SQL injection risk.

Question 4

Which technique is especially appropriate for testing values near the limits of an accepted range?

A. Boundary-value analysis

B. Randomized naming

C. Code formatting

D. License scanning

Correct Answer: A. Boundary-value analysis

Question 5

A test suite executes 80% of statements but fails to test whether unauthorized users are denied access. What is the best conclusion?

A. The application is proven secure because coverage exceeds 75%.

B. The untested authorization behavior represents a significant evidence gap.

C. Authorization cannot be tested automatically.

D. Statement coverage and authorization are identical measures.

Correct Answer: B. The untested authorization behavior represents a significant evidence gap.

Question 6

Which practice best protects stored user passwords?

A. Storing reversible encryption keys beside the password database

B. Storing passwords in plain text for administrative recovery

C. Using a maintained adaptive salted password-hashing mechanism

D. Encoding passwords with Base64

Correct Answer: C. Using a maintained adaptive salted password-hashing mechanism

Question 7

What does least privilege require?

A. Every authenticated user receives administrator permissions.

B. A component receives only the permissions necessary for its legitimate task.

C. Permissions are assigned permanently and never reviewed.

D. Authorization is performed only in the user interface.

Correct Answer: B. A component receives only the permissions necessary for its legitimate task.

Question 8

Which metric is represented by defects removed before release divided by total discovered defects, expressed as a percentage?

A. Mean time to restore

B. Defect removal efficiency

C. Statement coverage

D. Change failure rate

Correct Answer: B. Defect removal efficiency

Question 9

Why should production logs be reviewed for privacy risk?

A. Logs can never contain useful diagnostic information.

B. Logs may unintentionally retain personal data, credentials, or confidential content.

C. Logging automatically disables authentication.

D. Privacy regulations apply only to source code.

Correct Answer: B. Logs may unintentionally retain personal data, credentials, or confidential content.

Question 10

Which is an ethical requirement for an automated system making consequential decisions?

A. Prevent users from challenging any decision.

B. Collect all available personal data regardless of purpose.

C. Provide appropriate transparency, accountability, and avenues for correction.

D. Treat accessibility as optional when testing is complete.

Correct Answer: C. Provide appropriate transparency, accountability, and avenues for correction.

Programming in Visual Basic
Chapter 11 of 11