calling objects from other methods in java

stronghold051

I am a novice programmer and was wondering how I can create a test method that calls the object from the setUp() method above. Is there a better way to do this where a method is used to initialize the objects and the test method does the testing??

Any tips are appreciated..

public class ProjectTeamRemoveMemberTest {
    
    //Initialize test object
    public static void setUp() {
        Date date = new Date();
        Employee e = new Employee("Alice", date);
        Project p = new Project();
    }

    @Test
    public void removeTeamMember_True_ifMemberIsSelected() {
        setUp();
        assertEquals(true, p.removeTeamMember(e));
    }
}
Maciej Niedźwiedź

You can create those variables on class level, assign values in setup and refere to them in a test.

public class ProjectTeamRemoveMemberTest {
    
    static Date date;
    static Employee e;
    static Project p;

    //Initialize test object
    public static void setUp() {
        date = new Date();
        e = new Employee("Alice", date);
        p = new Project();
    }

    @Test
    public void removeTeamMember_True_ifMemberIsSelected() {
        assertEquals(true, p.removeTeamMember(e));
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling methods on objects Java

From Dev

Calling main methods in other objects in Scala

From Dev

Calling gamesclient methods from other actvities

From Dev

Using variables for creating objects and calling methods in Java

From Dev

Calling methods on objects in an arraylist

From Dev

Calling Parameterized Methods in Other Methods

From Java

Calling Java Methods from Shell Scripts

From Dev

Calling other class methods from __new__() in python

From Dev

calling generic methods with custom objects from list (automate)

From Dev

Calling variables from other classes in Java

From Dev

Java Calling function from other class async

From Java

Java use user input from other methods

From Dev

Javascript registry for calling methods and objects

From Dev

The right way to call methods from other objects when they are siblings

From Dev

Java, two objects, one cannot be resolved in methods, other can

From Dev

Calling methods with parameters inside other methods

From Dev

Calling methods inside other methods in Python

From Dev

XPages - Calling Java methods

From Dev

Calling the methods in java

From Dev

Calling Java Methods in XSLT

From Java

Calling multiple methods in Java

From Java

Calling the methods in a class in Java

From Java

Why calling methods from container class instead of instances of it in Java

From Java

Java: Calling in main implemented Interface Methods from a jUnit - Test

From Dev

Proper/easy way of calling methods from a program on remote server in java?

From Dev

Calling Java Methods from JNI results in program crash

From Java

Java Generics - calling specific methods from generic-typed ones

From Dev

Using a object in methods of other objects

From Dev

Java, Storing JSON Array to class and calling it from other class

Related Related

  1. 1

    Calling methods on objects Java

  2. 2

    Calling main methods in other objects in Scala

  3. 3

    Calling gamesclient methods from other actvities

  4. 4

    Using variables for creating objects and calling methods in Java

  5. 5

    Calling methods on objects in an arraylist

  6. 6

    Calling Parameterized Methods in Other Methods

  7. 7

    Calling Java Methods from Shell Scripts

  8. 8

    Calling other class methods from __new__() in python

  9. 9

    calling generic methods with custom objects from list (automate)

  10. 10

    Calling variables from other classes in Java

  11. 11

    Java Calling function from other class async

  12. 12

    Java use user input from other methods

  13. 13

    Javascript registry for calling methods and objects

  14. 14

    The right way to call methods from other objects when they are siblings

  15. 15

    Java, two objects, one cannot be resolved in methods, other can

  16. 16

    Calling methods with parameters inside other methods

  17. 17

    Calling methods inside other methods in Python

  18. 18

    XPages - Calling Java methods

  19. 19

    Calling the methods in java

  20. 20

    Calling Java Methods in XSLT

  21. 21

    Calling multiple methods in Java

  22. 22

    Calling the methods in a class in Java

  23. 23

    Why calling methods from container class instead of instances of it in Java

  24. 24

    Java: Calling in main implemented Interface Methods from a jUnit - Test

  25. 25

    Proper/easy way of calling methods from a program on remote server in java?

  26. 26

    Calling Java Methods from JNI results in program crash

  27. 27

    Java Generics - calling specific methods from generic-typed ones

  28. 28

    Using a object in methods of other objects

  29. 29

    Java, Storing JSON Array to class and calling it from other class

HotTag

Archive