chittiError: CompileError: Error parsing /Users/rahul/pet-shop-tutorial/test/TestAdoption.sol: ParsedContract.sol:10:1: ParserError: Expected pragma, import directive or contract/interface/library definition.
function testUserCanAdoptPet() public {
Compilation failed. See above.
    at async.whilst.error (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/profiler.js:369:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/async/dist/async.js:969:1
    at next (/usr/local/lib/node_modules/truffle/build/webpack:/~/async/dist/async.js:5222:1)
    at Promise.all.then.results (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/profiler.js:351:1)
Truffle v5.0.7 (core: 5.0.7)
Node v10.15.3

I see the confusion. The tutorial is asking you to add that method to the contract previously created in the tutorial. So at this step, your file all together should look like:

pragma solidity ^0.5.0;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Adoption.sol";

contract TestAdoption {
 // The address of the adoption contract to be tested
 Adoption adoption = Adoption(DeployedAddresses.Adoption());

 // The id of the pet that will be used for testing
 uint expectedPetId = 8;

 //The expected owner of adopted pet is this contract
 address expectedAdopter = address(this);

 // Testing the adopt() function
 function testUserCanAdoptPet() public {
   uint returnedId = adoption.adopt(expectedPetId);

   Assert.equal(returnedId, expectedPetId, "Adoption of the expected pet should match what is returned.");

Not the answer you're looking for? Browse other questions tagged or ask your own question.