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 8539241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:19:03+00:00 2026-06-11T11:19:03+00:00

I have a testcase that looks like this: def MyTestCase(unittest.Testcase): def test_input01(self): input =

  • 0

I have a testcase that looks like this:

def MyTestCase(unittest.Testcase):
  def test_input01(self):
    input = read_from_disk('input01')
    output = run(input)
    validated_output = read_from_disk('output01')
    self.assertEquals(output, validated_output)
  def test_input02(self):
    input = read_from_disk('input02')
    # ...
  # and so on, for 30 inputs, from input01 to input30

Now, I understand that test code can be a bit repetitive, since simplicity is more important than conciseness. But this is becoming really error-prone, since when I decided to change the signature of some functions used here, I had to make the change in all 30 places.

I could refactor this into a loop over the known inputs, but I do want each input to remain a separate test, so I thought I should be making the test_inputxx methods.

What am I doing wrong?

  • 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-11T11:19:04+00:00Added an answer on June 11, 2026 at 11:19 am

    Write a helper function to remove the repetition from the test cases:

    def MyTestCase(unittest.Testcase):
      def run_input_output(self, suffix):
        input = read_from_disk('input'+suffix)
        output = run(input)
        validated_output = read_from_disk('output'+suffix)
        self.assertEquals(output, validated_output)
    
      def test_input01(self): self.run_input_output('01')
      def test_input02(self): self.run_input_output('02')
      def test_input03(self): self.run_input_output('03')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers =
I have a class that looks like this public class TestCase { public IEnumerable<string>
I have a function in a module that looks something like this: module MyLibrary
I have a file that looks like this: A B C D E 0
I have a collection testcase like this, Test Builds have many Test Case Logs
I have a testdata like this: DROP TABLE SELECT_PASS; CREATE TABLE SELECT_PASS(ID INT(20),TESTCASE VARCHAR(20),RESULT
I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c
I have a test case: class LoginTestCase(unittest.TestCase): ... I'd like to use it in
I have a test case that looks like so: public class MyTest { private
This is a minimal test case of some code that I actually have. It

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.