Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:52:29+00:00 2026-06-09T10:52:29+00:00

I created a cooperation of 4 classes (Python). class A: ## A, B, C

  • 0

I created a cooperation of 4 classes (Python).

class A:
    ## A, B, C are nested classes of A
    class B:
        ...
    class C:
        ...
    class D:
        ...
    ## example methods
    def newB(self):
        return self.B()
    def newC(self):
        return self.C(self.newB())

I wrote 60 test-methods in 4 test-cases and this was hard work.

Because B, C, D do not offer much behaviour, the A, B, C, D classes shall be subclassed to add new behaviour.

The Problem:

I wrote much test code to ensure that A, B, C, D cooperate right.
If I subclass A, B, C, D to A2, B2, C2, D2 I will need to test the behaviour of A2, B2, C2, D2 in the same way I tested A, B, C, D.

How do I do this?

  1. subclass all unittests every time I create a new subclass of Database?
  2. generate the test cases and a suite by a method?
  3. …

What would be your practices to assure that the subclassed Database works correctly and there is no mistake in it?

Given: unittests, the classes of Database and your subclass(es)

Tests that exist now:

class TestA(unittest.TestCase):
    A = A
    def setUp(self):
        self.a = self.A()
    def test_something(self):
        ...

class MockB(A.B):
    ...
class AWithMock(A):
    B = MockB
class TestAWithMock(TestA):
    A = AWithMock
    def setUp(self):
        self.a = self.A()
    def test_something_new(self):
        ...

class MockB2(A.B):
    ...
class MockC2(A.C):
    ...
class MockD2(A.D):
    ...
class TestWithMock(unittest.TestCase):
    def test_b(self):
        b = MockB2()
        ...
    def test_c(self):
        ...
    def test_d(self):
        ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:52:31+00:00Added an answer on June 9, 2026 at 10:52 am
    import unittest
    class TestCaseA(unittest.TestCase):
        def setUp(self):
            self.thing = A()
    
        def test_does_x():
            self.assertTrue(self.thing.does_x())
    

    Now define a subclass A2:

    class A2(A):
        ...
    

    I would subclass your testcase but only override the setUp/setup method as the rest of the API of the subclass A2 should be consistent with A.

    So your test subclass would be just:

    class TestA2(TestCaseA):
        def setUp(self):
            self.thing = A2()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Created Private Key & Self signed certficate in a Key Store keytool -genkey -alias
I created a python server on port 8000 using python -m SimpleHTTPServer . When
I created a following class within a namespace Global namespace Global { public static
I have 3 classes A,B,C . Class A creates B .. class B creates
I've created a WebService like this: [WebService(Namespace = http://ns)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class
Our test department has a series of web tests created using Visual Studio 2005
I have two classes and two factories: class User belongs_to :company end class Company
I've a java program as shown below: package com.abc.myproject; import java.util.*; class test {
MANIFEST.MF Manifest-Version: 1.0 Created-By: 1.7.0_01 (Oracle Corporation) Main-Class: useDisplay NOTE: There is a blank
Created .NET WCF service, tested it - works. Generated schemas from Data and service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.