Showing posts with label junit. Show all posts
Showing posts with label junit. Show all posts

28 September 2017

Coolpointer.019 Unit test naming convensions



      7 Popular Unit Test Naming Conventions by Ajitesh Kumar shows few naming conversions for unit test. I used different conversion.  I follow Phil Webb's approach which is methodNameShouldExpectedBehavior. I tried few ways that I learnt on web and at work but this method works best for me as it helps me identify precisely what I am testing, where and what result I expect, so when test fails it helps me look to root of problem quicker.


methodName is my "when" which explain me what I am testing
ExpectedBehavior is my "then"
and optionally I added given which is my "Given?"

for example:
methodNameShouldPerformExpectedBehaviourWhenThisConditionOccured




7 Popular Unit Test Naming Conventions by Ajitesh Kumar  







9 April 2016

How to solve problem java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V gradle ?

PROBLEM:

When I practised TDD  I used added all libs manually(simply ask IntelliJ to take care of) , but I decided use gradle.I added  hamcrest ,junit (and Mockito ) and when I run gradle refresh ... I saw this:
java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
I couldn't figure out for a little bit why this happen and then I tried change order of  dependencies and that solved problem (I remembered ,I had similar problem in the past in other project).

SOLUTION:

Make sure  you put hamcrest dependencies before junit

dependencies {

    (...)   
    compile 'org.hamcrest:hamcrest-all:1.3'

    compile 'junit:junit:4.12'
    (...)

}

Done! Have an epic day/night fellow developer!

3 April 2013

How to solve problem with error javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist

I trying to use yml to create a temp database for test purposes.
Address(A1):
 
id: 1
  nickname: "an address"
  line_1: "Somewhere"
  line_2: " Lollypop factory "
  line_3: "funky factory"
  town: "Sugarfree town"
  county: "Country"
  postcode: "UK1 LOL"


So you copy record from database into yml and you see this weird message:

javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist:

  with lots meaningless stack trace.

Problem in this case is that ... hibernate fails if the id was already assigned,because id is automatically assigned.

Good to know...

Source: http://stackoverflow.com/questions/15198675/javax-persistence-persistenceexception-org-hibernate-persistentobjectexception