Skip to main content
added 6 characters in body
Source Link
user3797758
  • 3.7k
  • 2
  • 31
  • 53

I need to create some tests for a bunch of variables that are initialized via the editor, So in the script they are always null and can't be set publicly.

Usually using the tag is a good way to encapsulate the code but with tests how do I check such a variable? Example:

public class thing 
{
    [SerializeField]
    private string line;

    //constructor(s), methods, etc..    
    
    public void setLine(string text){line = text; }
}

How do I check the value of the string after it is set inside a test?
(preferably without creating a getter method)

I need to create some tests for a bunch of variables that are initialized via the editor, So in the script they are always null and can't be set publicly.

Usually using the tag is a good way to encapsulate the code but with tests how do I check such a variable? Example:

public class thing{
    [SerializeField]
    private string line;

    //constructor(s), methods, etc..    
    
    public void setLine(string text){line = text; }
}

How do I check the value of the string after it is set inside a test?
(preferably without creating a getter method)

I need to create some tests for a bunch of variables that are initialized via the editor, So in the script they are always null and can't be set publicly.

Usually using the tag is a good way to encapsulate the code but with tests how do I check such a variable? Example:

public class thing 
{
    [SerializeField]
    private string line;

    //constructor(s), methods, etc..    
    
    public void setLine(string text){line = text; }
}

How do I check the value of the string after it is set inside a test?
(preferably without creating a getter method)

readability
Source Link
user3797758
  • 3.7k
  • 2
  • 31
  • 53

I need to create some tests for a bunch of itemsvariables that are initialized via the editor, So in the script they are always null and can't be set publicly.

Usually using the tag is a good way to encapsulate the code but with tests how do I check such a variable? Example:

public class thing{
    [SerializeField]
    private string line;

    //constructor(s), methods, etc..    
    
    public void setLine(string text){line = text; }
}

How do I check the value of the string after it is set inside a test?
(preferably without creating a getter method)

I need to create some tests for a bunch of items that are initialized via the editor, So in the script they are always null and can't be set publicly.

Usually using the tag is a good way to encapsulate the code but with tests how do I check such a variable? Example:

public class thing{
    [SerializeField]
    private string line;

    //constructor(s), methods, etc..    
    
    public void setLine(string text){line = text; }
}

How do I check the value of the string after it is set inside a test?
(preferably without creating a getter method)

I need to create some tests for a bunch of variables that are initialized via the editor, So in the script they are always null and can't be set publicly.

Usually using the tag is a good way to encapsulate the code but with tests how do I check such a variable? Example:

public class thing{
    [SerializeField]
    private string line;

    //constructor(s), methods, etc..    
    
    public void setLine(string text){line = text; }
}

How do I check the value of the string after it is set inside a test?
(preferably without creating a getter method)

Source Link
user3797758
  • 3.7k
  • 2
  • 31
  • 53

How do you create test for unity variables that are set through the [SerializeField] tag?

I need to create some tests for a bunch of items that are initialized via the editor, So in the script they are always null and can't be set publicly.

Usually using the tag is a good way to encapsulate the code but with tests how do I check such a variable? Example:

public class thing{
    [SerializeField]
    private string line;

    //constructor(s), methods, etc..    
    
    public void setLine(string text){line = text; }
}

How do I check the value of the string after it is set inside a test?
(preferably without creating a getter method)