Skip to main content

I am writing a set of junit test classes in Java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and every test class would implement it.

The benefits I see there are:

  • easy access to constants: MY_CONSTANT instead of ThatClass.MY_CONSTANT
  • each constant defined only once

Is this approach rather a good or bad practice? I feel like doing so is a little like abusing the concept of interfaces a little bit.

You can answer generally about interfaces/constants, but also about unit tests if there is something special about it.

I am writing a set of junit test classes in Java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and every test class would implement it.

The benefits I see there are:

  • easy access to constants: MY_CONSTANT instead of ThatClass.MY_CONSTANT
  • each constant defined only once

Is this approach rather a good or bad practice? I feel like abusing the concept of interfaces a little bit.

You can answer generally about interfaces/constants, but also about unit tests if there is something special about it.

I am writing a set of junit test classes in Java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and every test class would implement it.

The benefits I see there are:

  • easy access to constants: MY_CONSTANT instead of ThatClass.MY_CONSTANT
  • each constant defined only once

Is this approach rather a good or bad practice? I feel like doing so is a little like abusing the concept of interfaces.

You can answer generally about interfaces/constants, but also about unit tests if there is something special about it.

edited tags
Link
Laiv
  • 15k
  • 2
  • 34
  • 72
Question Protected by gnat

I am writing a set of junit test classes in javaJava. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and every test class would implement it.

The benefits I see there are:

  • easy access to constants: "MY_CONSTANT"MY_CONSTANT instead of "ThatClass.MY_CONSTANT"ThatClass.MY_CONSTANT
  • each constant defined only once

Is this approach rather a good or bad practice? I feel like abusing the concept of interfaces a little bit.

You can answer generally about interfaces/constants, but also about unit tests if there is something special about it.

I am writing a set of junit test classes in java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and every test class would implement it.

The benefits I see there are:

  • easy access to constants: "MY_CONSTANT" instead of "ThatClass.MY_CONSTANT"
  • each constant defined only once

Is this approach rather a good or bad practice? I feel like abusing the concept of interfaces a little bit.

You can answer generally about interfaces/constants, but also about unit tests if there is something special about it.

I am writing a set of junit test classes in Java. There are several constants, for example strings that I will need in different test classes. I am thinking about an interface that defines them and every test class would implement it.

The benefits I see there are:

  • easy access to constants: MY_CONSTANT instead of ThatClass.MY_CONSTANT
  • each constant defined only once

Is this approach rather a good or bad practice? I feel like abusing the concept of interfaces a little bit.

You can answer generally about interfaces/constants, but also about unit tests if there is something special about it.

Tweeted twitter.com/#!/StackProgrammer/status/592027827995815936
Source Link
FabianB
  • 932
  • 1
  • 7
  • 8
Loading