nus-cs2103-AY2425S1 / forum

12 stars 0 forks source link

Assertions problem #263

Closed verakohh closed 2 months ago

verakohh commented 2 months ago

Hi! How do i know if my assertions are working after setting them up?

image

I've added the -ea VM option for my ip[run] but when i run the code below and make a new task, there are no errors shown. I'm not sure if it's not set up properly or if i'm not applying the assertions correctly.

 public Task(String description) {
        this.description = description;
        this.isDone = false;
        assert isDone == true : "Task should not be marked done yet.";
    }
winstonlimjy commented 2 months ago

Maybe you could set an assert false; to the start of the run method to see if the program crashes at the start of the program?

verakohh commented 2 months ago
image
    public String run() {
        assert false : "assert works";
        String greeting = ui.displayWelcomeMessage();
        return greeting;
    }

i get the above error when i insert it into my file.

image
winstonlimjy commented 2 months ago

Are you running with gradle? Did you add this

run {
    enableAssertions = true
}

to your build.gradle file

verakohh commented 2 months ago
image

Oh i didnt add that but after i did and ran with gradle, i did get an assertion error as one of the errors.

Thank you so much!! @winstonlimjy