REF added testEnvironment and adopted code of PSDemo to it.