JUnit, assert multiple values

Posted on 2009-12-29
Last Modified: 2013-12-15
I have two posibilies for a defined int  to be true. How can i use something like this

int actual = getActualInt();

Assert.assertEquals(actual, 1); or  Assert.assertEquals(actual, 2);

Question by:mertez
    LVL 26

    Expert Comment

    Assert.assertTrue( ( actual == 1 || actual == 2 ) );

    Author Comment

    is there any difference between assertTrue and assertEquals?

    thank you
    LVL 26

    Accepted Solution

    assertTrue - just check the value is true/false
    assertEquals - compares two values for equalness
    LVL 40

    Expert Comment

    assertTrue tells if the conditions are true

    assertEquals tells if the parameters passed to the method are equal or not

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    The viewer will learn how to implement Singleton Design Pattern in Java.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now