• Post Reply Bookmark Topic Watch Topic
  • New Topic

TDD and constants  RSS feed

 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi @ll,

I am trying to test the value of a constant using TDD.





Both test and class are in the same package

Any idea, please?

Regards, Isaac
 
Liutauras Vilda
Marshal
Posts: 4650
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you getting any error messages? In case yes, please copy & paste them here.
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, just the variable choice doesnt appears for the object PlayerA
 
Ole Sandum
Ranch Hand
Posts: 76
3
IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few points about the code:

Are the test class and the tested class in the same package? They will have to be if you want to access the choice field, since it is package-local.

Why is it package-local, though? Surely, if it's a constant it should be public.

Constants should be named with all caps.

Why are you creating a new object to access the field? It is static.

The name 'choice' sounds like that is supposed to be an instance field...? Maybe you should think of a better name for it?

Why do you feel like testing the value of a constant? What is the motivation for this?
 
Liutauras Vilda
Marshal
Posts: 4650
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac DurĂ¡ wrote:No, just the variable choice doesnt appears for the object PlayerA

Because you haven't created PlayerA object properly, missing '()'. Anyway, you don't need an instance as your variable 'choice' is static. So you should be able to access it via class name.
 
Isaac Ferguson
Ranch Hand
Posts: 1063
3
Java Netbeans IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now works...I assumed  that it was public by default...

Thanks for the tips... now it works and looks better
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!