Teams: How to Add Throws IOException to JUnit Test

I apologize for the cross-posting, but I perhaps shouldn’t have put my original request on Code Help. I’m a teacher writing JUnit tests for my assignments. One of my tests needs to have “throws IOException” after the method header, but I can’t add to that line (the cursor won’t let me type there). Here’s the code I have in the system:

public void NotUsingMathClassTest ( ) {

        int count = 0;
        String learner_code = new String(Files.readAllBytes(Paths.get("Main.java")));
        String[] words = learner_code.split(" ");
        System.out.println(words.length);
        for (int i = 0; i < words.length; i++) 
            {
            if (words[i].indexOf("Math.") >= 0) 
                {
                count++;
                }
            }
        assertFalse(count > 0);
          }
}

It works in another IDE if the method header reads public void NotUsingMathClassTest ( ) throws IOException.

2 Likes

Have you tried copying and pasting it into another program? Some people are coming across issues where they just need to move their code to another program to get it to work. Move as in copy and paste, forking it will still have the problem.

Good thought, but I can never add anything to the method header, or anything before the opening curly brace.

Do you have this in a replit program you can invite me to?

Hey, thanks so much for following up. It’s automatically private as a Teams project. Can you access it with this student link? https://replit.com/team/APCS-23-24/Evaluating-Exponents

Nope, It just brings me to my main page of replit

OK, I forked it out of Teams and made it public. Here it is: https://replit.com/@MikeMcGuire1/Evaluating-Exponents-CR

I figured out a workaround - adding try/catch handling within the method instead of adding something to the method header.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.