Java Unit Test Read File

Question:
Hi everyone,

I am new to using Unit Test. I saw a YouTube video for Coding Rooms that allows the teacher to test if the student code contains a specifc String. I tried it in a repl but could not get it to work.

Here is his code:

I tried using the code but could not get it to work. I think it is because of the header in my repl. I could NOT type “throws Exception”.

Please help…

Thank you,
Tyler

Hello @TylerTrinh and welcome to the community!

Could you please share the repl to your code so we can analyse and check if everything is ok?

You can check this guide about how to share your code.

My Repl Linkis >>> https://replit.com/@tntrinh/DeleteLaterUnit4

Hopefully you are able to see my Dog.java code as well as the unit test that I need help with.

I ran the unit test and got the following error message:

Installing imported packages
Failed to compile test runner file

./_test_runnerTestSuite.java:13: error: unreported exception IOException; must be caught or declared to be thrown
      String student_code = new String(Files.readAllBytes(Paths.get("Dog.java")));
                                                         ^
Note: ./_test_runnerTestRunner.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error


exit status 1

Is this a private repl? I clicked the link and got a 404

1 Like

I believe all of my Repls are public, but I might have forgotten to publish it. I believe it should be okay now for you to access.

Thanks for your time.

“This person doesn’t have any Repls yet!”
https://replit.com/@tntrinh